开发者

Drag and Drop - How to get the DragSource on the DragStart event

开发者 https://www.devze.com 2023-03-27 01:29 出处:网络
When I start a drag operation I would like to be able to highlight the possible valid Drop objects. For this I need to know when the drag operation starts and which items are being dragged. I am tryin

When I start a drag operation I would like to be able to highlight the possible valid Drop objects. For this I need to know when the drag operation starts and which items are being dragged. I am trying to do this using the dragStart, but the event.dragSource is null on this event.

I have this list:

<s:List
    width="100%"
    height="100%"
    id="productsListing" 
    dragEnabled="true"
    dataProvider="{products}"
    dragStart="dragStartHandler(event);"
    dragComplete="dragCompleteHandler(event);"
    itemRenderer="views.productListed" />

And I have 开发者_Go百科the listener as:

public function dragStartHandler(event:DragEvent):void {
    var itemsVector:Vector.<Object> = event.dragSource.dataForFormat('itemsByIndex') as Vector.<Object>;
    //Verify Items
    //Highlight appropriated dropZones
}

Anyone have a good sugestion how to overcome this?


The problem here is that your dragStartHandler is taking higher precedence than the List components internal dragStartHandler - which is where the drag operation is started and the dragSource property created.

Suggestion, manually add your dragStartHandler with a lower precedence than the List components dragStartHandler method - looking at the code this needs to be less than -50.

MXML Code:

<s:List width="100%" height="100%"
        id="productsListing"  
        dragEnabled="true"   
        dataProvider="{products}"
        initialize="productsListing_initializeHandler(event)"
        dragComplete="productsListing_dragCompleteHandler(event)"
        itemRenderer="views.productListed"
        />

AS Code:

protected function productsListing_initializeHandler(event:FlexEvent):void
{
    // Needs to be handled AFTER the List component has handled the event and attached the dragSource data, hence priority is -51
    this.productsListing.addEventListener(DragEvent.DRAG_START, productsListing_dragStartHandler, false, -51, true);
}

protected function productsListing_dragStartHandler(event:DragEvent):void
{
    // Your code here...
}

I hope you find that useful.


This is the in built solution for drag drop in flex

we can implement the Object Handles for all component it is easy to drag, drop and resize.

refer this http://code.google.com/p/flex-object-handles/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号