2009-02-26 56 views
1

我正在使用HorizontalList组件显示图像列表,您可以从另一个组件拖动图像以加入列表,这一切都正常。Flex/AS3拖放 - 自定义拖放反馈

如果我做list.showDropFeedback(event)我得到的图像在HorizontalList顶难看的黑条 - 我真正想要的是一条线的形象,在新的人会真正坐下的左/右。

我想我需要定义一个自定义DropFeedback来覆盖默认值。有谁知道是否有办法实现这一目标?

谢谢!

回答

3

尤奥可以通过重写showDropFeedback()方法来克服它。我的代码如下:

import mx.controls.HorizontalList; 
import mx.controls.listClasses.IListItemRenderer; 
import mx.core.mx_internal; 
import mx.events.DragEvent; 

use namespace mx_internal; 

public class HList extends HorizontalList 
{ 
    public function HList() 
    { 
     super();       
    } 


     override public function showDropFeedback(event:DragEvent):void 
     { 

      super.showDropFeedback(event); 

      dropIndicator.setActualSize(rowHeight - 4, 4); 
      DisplayObject(dropIndicator).rotation = 90; 

     } 



} 
+0

我没有足够的代表编辑您的文章,但请注意前两个导入语句未包含在代码块中。你应该解决这个问题。 – 2009-05-06 20:07:23

1

有一个名为dropIndicatorSkin的样式属性,它控制在拖动基于列表的组件时显示的行的外观。 从Adobe的文档:

dropIndicatorSkin

的皮肤使用,以指示所拖动项目被删除。当ListBase派生的组件是拖放操作中的潜在拖放目标时,调用showDropFeedback()方法将生成此类的一个实例,并将其放置在该项目的itemRenderer之上一个像素,其中如果发生拖放,是丢弃项目后的项目。默认值是mx.controls.listClasses.ListDropIndicator

所有的功能都内置到Horizo​​ntalList中去完成你所要求的功能,但是似乎在Horizo​​ntalList中有一个错误,它并没有将其方向属性设置为水平。

所有你需要做的就是把方向=“横向”在MXML声明中,就旋转dropIndicatorSkin 90度,poistion它在项目之间,而不是在他们之上:

<mx:HorizontalList ... direction="horizontal" ... /> 
0

谢谢,这似乎按预期旋转dropIndicator,但会产生其他非常意外的行为。列表上的水平滚动条突然消失,并将一个项目拖动到列表中,使其直接跳到最后....感觉就像我几乎在那里,但不完全!

我的AS3代码....

// in constructor... (extends HorizontalList) 
this.direction = "horizontal"; 

this.addEventListener(DragEvent.DRAG_ENTER, onDragEnter); 
this.addEventListener(DragEvent.DRAG_OVER, onDragOver); 
this.addEventListener(DragEvent.DRAG_EXIT, onDragExit); 
this.addEventListener(DragEvent.DRAG_DROP, onDragDrop); 

private function onDragEnter(event:DragEvent):void { 
    event.preventDefault(); 
    if (event.dragSource.hasFormat("treeItems") || event.dragSource.hasFormat("items")) { 
     DragManager.acceptDragDrop(event.target as UIComponent); 
    } 
    this.showDropFeedback(event); 
} 

public function onDragOver(event:DragEvent):void { 
    event.preventDefault(); 
    this.showDropFeedback(event); 
} 

public function onDragExit(event:DragEvent):void { 
    event.preventDefault(); 
    this.showDropFeedback(event); 
} 

private function onDragDrop(event:DragEvent):void { 
    event.preventDefault(); 
    this.hideDropFeedback(event); 
    //.... 
} 
+0

您是否有特别的原因要求您自己调用preventDefault()并执行showDropFeedback()和hideDropFeedback(),或者您是否试图手动绘制指示符? – 2009-02-27 17:16:21

+0

删除它们似乎有一点帮助。但是现在我的Horizo​​ntalList似乎更像一个TileList,即。 3行3而不是9行1行 - 到达那里,慢慢地...... – adam 2009-03-04 08:57:37

2

我解决了这个最终被添加在我的申请方式如下..

HorizontalList { 
dropIndicatorSkin: ClassReference("com.package.HorizontalListDropIndicator"); 
} 

和创建我的自定义皮肤..

package com.package { 

import flash.display.Graphics; 
import mx.skins.ProgrammaticSkin; 

public class HorizontalListDropIndicator extends ProgrammaticSkin { 

    public function HorizontalListDropIndicator() { 
    super(); 
    } 

    override protected function updateDisplayList(w:Number, h:Number):void { 
    super.updateDisplayList(w, h); 

    var g:Graphics = graphics; 

    g.clear(); 
    g.lineStyle(2, 0xFF0000); 

    g.moveTo(0, 0); 
    g.lineTo(0, 250); 

    } 
} 
} 
2

看起来这是在Flex框架的错误:

Flex Builder 3/sdks/3.3.0/frameworks/projects/framework/src/mx/controls/HorizontalList.as(线95-105)

public function HorizontalList() 
{ 
    super(); 

    _horizontalScrollPolicy = ScrollPolicy.AUTO; 
    _verticalScrollPolicy = ScrollPolicy.OFF; 

    direction = TileBaseDirection.VERTICAL; 
    maxRows = 1; 
    defaultRowCount = 1; 
} 

注意,构造函数Horizo​​ntalList将是初始化方向值为垂直

一个快速简便的解决办法是简单地在你的MXML指定direction="horizontal"

<mx:HorizontalList id="fooLst" direction="horizontal" dataProvider="{foo}" /> 

如果这个bug尚未固定的(并等待下一个版本),我会感到很惊讶,但如果没有记录,我会检查Flex SDK bug database并提交报告。