1

Flex 为列表控件内置了拖放功能,并允许您覆盖它。但他们没有在示例中涵盖这一点。内置功能会自动拖动列表项,如果您想覆盖它,您会发现处理程序正在列表本身上设置。我特别想做的是,我的 TileList 显示了我可以拖动到大画布上的项目的小缩略图。当我从列表中拖动一个项目时,拖动代理应该是不同的图像。

所以,我遵循了建议的技术,它只有在我明确设置代理图像的宽度/高度时才有效。为什么?

4

2 回答 2

3

在您尝试之前并不明显 =) 几周前我也在为同样的事情苦苦挣扎。这是我的解决方案:

名单:

<List>
  <mouseDown>onListMouseDown(event)</mouseDown>
</Tree>

鼠标按下处理程序:

private function onMouseDown( event : MouseEvent ) : void {
  var list : List = List(event.currentTarget);

  // the data of the clicked row, change the name of the class to your own
  var item : MyDataType = MyDataType(list.selectedItem);

  var source : DragSource = new DragSource();

  // MyAwsomeDragFormat is the key that you will retrieve the data by in the
  // component that handles the drop
  source.addData(item, "MyAwsomeDragFormat");

  // this is the component that will be shown as the drag proxy image
  var dragView : UIComponent = new Image();

  // set the source of the image to a bigger version here
  dragView.source = getABiggerImage(item);

  // get hold of the renderer of the clicked row, to use as the drag initiator
  var rowRenderer : UIComponent = UIComponent(list.indexToItemRenderer(list.selectedIndex));

  DragManager.doDrag(
    rowRenderer,
    source,
    event,
    dragView
  );
}

当用户单击列表中的项目时,这将开始拖动。请注意,我没有dragEnabled在列表中设置和其他与拖动相关的属性,因为我自己处理所有这些。

将其添加到事件处理程序的开头会很有用:

if ( event.target is ScrollThumb || event.target is Button ) {
  return;
}

如果用户单击滚动条中的某处,则只是为了短路。它不是很优雅,但可以完成工作。

于 2008-09-16T18:37:13.800 回答
1

我在这里找到了一个更简单的答案。该示例扩展了 DataGrid 控件,但您可以对 List 控件执行相同操作。就我而言,我使用图像源而不是类:

public class CustomDragList extends List {

    [Bindable]
    public var dragProxyImageSource:Object;

    override protected function get dragImage():IUIComponent {
        var image:Image = new Image();
        image.width = 50;
        image.height = 50;
        image.source = dragProxyImageSource;
        image.owner = this;
        return image;
    }
}

然后像这样使用该自定义列表:

<control:CustomDragList
    allowMultipleSelection="true"
    dragEnabled="true" 
    dragProxyImageSource="{someImageSource}"
    dragStart="onDragStart(event)"/>

其中“someImageSource”可以是您通常用于图像源的任何内容(嵌入的、链接的等)

于 2010-02-02T15:20:41.357 回答