In this example you can see how we can drag and drop the component from one place to another.
In this example you can see how we can drag and drop the component from one place to another.In this example you can see how we can drag and drop the
component from one place to another. There are the three classes of drag and
drop operation:
1. DragManager: It manages the drag and drop operation using doDrag() method.
2. DragSource: It contains the data which is dragged.
3. DragEvent: It represent the drag and drop events.
In this example we will drag and drop a Button control in a Panel from one place
to another.
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> <fx:Script> <![CDATA[ import mx.managers.DragManager; import mx.core.DragSource; import mx.events.DragEvent; import flash.events.MouseEvent; // initialize the drag and drop operation private function mouseMoveHandler(event:MouseEvent):void { var dragInitiator:Button=Button(event.currentTarget); var dragSource:DragSource = new DragSource(); dragSource.addData(dragInitiator, "button"); DragManager.doDrag(dragInitiator, dragSource, event); } private function dragEnterHandler(event:DragEvent):void { if (event.dragSource.hasFormat("button")) { DragManager.acceptDragDrop(Panel(event.currentTarget)); } } private function dragDropHandler(event:DragEvent):void { Button(event.dragInitiator).x = Panel(event.currentTarget).mouseX; Button(event.dragInitiator).y = Panel(event.currentTarget).mouseY; } ]]> </fx:Script> <s:Panel title="Flex component move using drag and drop" width="386" height="282" chromeColor="#555555" color="#CCCCCC" dragEnter="dragEnterHandler(event);" dragDrop="dragDropHandler(event);"> <s:Button id="btn" label="Drag Button" mouseMove="mouseMoveHandler(event)"/> </s:Panel> </s:Application> |
To view this page ensure that Adobe Flash Player version 10.0.0 or greater is installed.