Dragging from a Tree to a List/TileList
In the Flex framework, we have made dragging and dropping within various List components fairly trivial. Assuming that your data is similar, you simply need to add dragEnabled=true to your source and then dropEnabled=false for your destination. However, the one exception in this case is Tree. By default, you cannot drag any items from any other drag enabled List component (other than another tree). If you look at the source of the framework, you will see that all of the event handlers used for TileList, List, HorizontalList and DataGrid are in ListBase.as. However, Tree has its own custom drag event handlers. Therefore, if you want to share data between another List component and a Tree using drag and drop, you will need to override all of the drag event handlers. These handlers include dragEnter, dragDrop, dragComplete and dragOver. Here is an example Application where you can drag items from a Tree to a TileList. The items will be removed from the Tree.
Here is the code for the Tree and TileList:
And here are my event handlers for each drag events:
public function doDragOver(event:DragEvent) : void
{ event.preventDefault();DragManager.showFeedback(event.ctrlKey ? DragManager.COPY : DragManager.MOVE); TileList(event.target).showDropFeedback(event); }public function doDragEnter(event:DragEvent): void { event.preventDefault();DragManager.acceptDragDrop(TileList(event.target)); DragManager.showFeedback(event.ctrlKey ? DragManager.COPY : DragManager.MOVE); TileList(event.target).showDropFeedback(event); } public function doDragDrop(event:DragEvent): void
var items:Array = event.dragSource.dataForFormat(”treeItems”) as Array;
public function doDragComplete(event:DragEvent): void
//do the remove
private function getChildIndexInParent(parent:Object, child:Object, target:Tree):int
|
Demo: TileList2Tree.swf
Source code: TileList2Tree.mxml
9:42 AM
|
Labels:
Flex DataGrid Samples,
Flex Samples
|
This entry was posted on 9:42 AM
and is filed under
Flex DataGrid Samples
,
Flex Samples
.
You can follow any responses to this entry through
the RSS 2.0 feed.
You can leave a response,
or trackback from your own site.
1 comments:
my Dilemma is actrually the opposite. Dragging from a container to a tree component. any ideas?
Post a Comment