VBox drag events
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
backgroundColor="white">
<mx:Script>
import mx.core.DragSource;
import mx.managers.DragManager;
import mx.events.*;
import mx.controls.Button;
import mx.collections.ArrayCollection;
[Bindable]
public var myAC:ArrayCollection = new ArrayCollection([
{name:"A", price:1.5},
{name:"B", price:1.8}]);
public function initiateDrag(event:MouseEvent):void
{
var dragInitiator:Button=Button(event.currentTarget);
var ds:DragSource = new DragSource();
ds.addData(dragInitiator.label,"name");
DragManager.doDrag(dragInitiator, ds, event);
}
public function handleDragEnter(event:DragEvent):void
{
DragManager.acceptDragDrop(event.currentTarget as VBox);
}
public function handleDragOver(event:DragEvent):void
{
if (event.shiftKey)
{
DragManager.showFeedback(DragManager.LINK);
event.currentTarget.setStyle('borderColor', 'green');
}
}
public function handleDrop(event:DragEvent):void
{
var newButton:Button = new Button();
newButton.label = event.dragSource.dataForFormat("name") as String;
droppableArea.addChild(newButton);
droppableArea.setStyle('borderColor','black');
if(event.action == DragManager.MOVE)
buttonPanel.removeChild(event.dragInitiator as Button);
}
public function handleDragExit(event:DragEvent):void
{
droppableArea.setStyle('borderColor','black');
}
</mx:Script>
<mx:VBox id="buttonPanel">
<mx:Label text="Drag the buttons into the box to copy them in" />
<mx:Button label="A" mouseMove="initiateDrag(event)" />
</mx:VBox>
<mx:VBox id="droppableArea"
borderColor="black"
dragEnter="handleDragEnter(event)"
dragOver="handleDragOver(event)"
dragDrop="handleDrop(event)"
dragExit="handleDragExit(event)"
width="94"
height="76"
backgroundColor="#D7FE2E"
borderStyle="solid" />
</mx:Application>
Related examples in the same category