2011-08-05 44 views
1

我有一個接受drop的列表。當一個項目被刪除(DragEvent.DRAG_DROP)我需要收集被刪除的數據,但是我沒有發現任何事情可以幫助我這樣做,event.dragInitiator.selectedItems會工作,但給我一個錯誤。Flex檢測拖拽數據

任何幫助,將不勝感激。

回答

2

該數據應該在event.dragSource。您必須使用hasFormat()檢查正確的格式,並使用dataForFormat()檢索它。這裏是DragSource的文檔。

代碼會是這樣的(假設這是Flex 4中):

// In dragDrop handler or dragComplete 
if (event.dragSource.hasFormat("itemsByIndex")) 
{ 
    var items:Vector.<Object> = event.dragSource.dataForFormat("itemsByIndex") as Vector.<Object>; 
    // Do stuff with items 
} 
+0

是的,做到了,謝謝。 –

0

您還可以收聽改變數據提供程序。

list.dataProvider.addEventListener(CollectionEvent.COLLECTION_CHANGE, list_dataProvider_change); 

... 

protected function list_dataProvider_change(e :CollectionEvent) :void 
{ 
    if (e.kind == CollectionEventKind.REMOVE) 
     trace('list element removed from - index', e.location); 
    else if (e.kind == CollectionEventKind.ADD) 
     trace('list element added to - index', e.location); 
}