Apache flex 如何动态加载图像进行拖放?

Apache flex 如何动态加载图像进行拖放?,apache-flex,air,Apache Flex,Air,我正在Flex3 AIR应用程序中实现从数据网格到列表的拖放。我希望拖动图像是由数据网格项中名为“imagePath”的字符串字段引用的照片(jpg)。我在拖动过程中无法显示图像。我已经三次检查,这不是因为图像的路径无效。我已经用我能想到的各种方法尝试了Image的source()和load()方法。我在mouseDown事件上调用此方法“dragCurrentToList(event)” private function dragCurrentToList(event:MouseEvent):

我正在Flex3 AIR应用程序中实现从数据网格到列表的拖放。我希望拖动图像是由数据网格项中名为“imagePath”的字符串字段引用的照片(jpg)。我在拖动过程中无法显示图像。我已经三次检查,这不是因为图像的路径无效。我已经用我能想到的各种方法尝试了Image的source()和load()方法。我在mouseDown事件上调用此方法“dragCurrentToList(event)”

private function dragCurrentToList(event:MouseEvent):void 
{                
    var current:Object = event.currentTarget.selectedItem;

    var dragImg:Image = new Image();
    dragImg.load(current.imagePath);
    dragImg.width = 100; 
    dragImg.width = 100;

    var dsource:DragSource = new DragSource();
    dsource.addData(current, 'record');

    DragManager.doDrag(event.currentTarget as DataGrid, dsource, event, dragImg);
}
如果我将图像源设置为以下可绑定变量,但我不想硬编码图像名称,那么这将非常有效

[Bindable] 
[Embed(source='assets/icons/default.jpg')]
public var dragIcon:Class;

...
dragImg.source = dragIcon
...  

在dragCurrentToList方法中,为什么要加载图像,而不只是将源属性指定为图像的URL


还要确保您正在响应dragStart事件。( ). 我相信不是访问DragManager类;您只需修改dragStart事件的dragSource属性即可

谢谢,不过我试过了。也许是因为imagePath不是一个类?我尝试过:dragImg.source=contact.imagePath;和dragImg.source=“assets/icons/default.jpg”;和dragImg.source=“@Embed(source='assets/icons/default.jpg')”它们都有相同的行为。拖动时不显示任何内容,控制台中也不显示任何内容。是的,我切换到对dragStart的响应。有道理。我收回关于使用dragStart per Okay的部分,我从Flextras DataSorter中提取了代码,在那里我使用了类似的方法[我们动态生成位图数据;但不引用项目中的图像数据]。dragImage数据在dragStartHandler中使用DragManager.doDrag函数进行设置。但是,德拉吉是一个获得者。您可以覆盖dragImage getter,而不使用dragStartEvent进行清理。但是,如果您确实决定使用dragEvent,请确保覆盖现有的dragStartHandler,这样您就不会有两个相互竞争的代码段试图设置dragImage。
private function dragCurrentToList(event:MouseEvent):void 
{                
    var current:Object = event.currentTarget.selectedItem;

    var dragImg:Image = new Image();
    dragImg.source = current.imagePath;
    dragImg.width = 100; 
    dragImg.width = 100;

    var dsource:DragSource = new DragSource();
    dsource.addData(current, 'record');

    DragManager.doDrag(event.currentTarget as DataGrid, dsource, event, dragImg);
}