<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="init()" layout="absolute">
<mx:Style>
Application{
fontSize:12pt;
}
</mx:Style>
<mx:Script>
<![CDATA[
import mx.events.DragEvent;
import mx.core.DragSource;
import mx.managers.DragManager;
private function init():void{
}
private function dragIt(e:MouseEvent):void{
var myCanvas:Canvas=e.currentTarget as Canvas;
var dataSource:DragSource=new DragSource();
dataSource.addData(e.currentTarget,"obj");
DragManager.doDrag(myCanvas,dataSource,e);
}
private function dragEnter(e:DragEvent):void{
var dropTarger:HBox=e.currentTarget as HBox;
DragManager.acceptDragDrop(dropTarger);
}
private function dragDrop(e:DragEvent):void{
var obj:Canvas=e.dragSource.dataForFormat("obj") as Canvas;
setCount(e.currentTarget as HBox,obj);
//var tb:HBox=(e.currentTarget as HBox);
//tb.addChild(obj);
//trace(e.currentTarget.toString());
//myCanvas.addChild(e.currentTarget as DisplayObject);
}
private function setCount(hbox:HBox,cas:Canvas):void{
hbox.addChild(cas);
if(hbox.id=="sellList"){
trace("sell");
}else{
trace("buy");
}
}
]]>
</mx:Script>
<mx:VBox id="myVBox" x="200" y="200">
<mx:HBox id="sellList" backgroundColor="white" width="100" height="50" dragEnter="dragEnter(event)" dragDrop="dragDrop(event)">
<mx:Canvas id="red" width="20" height="20"
borderStyle="solid" backgroundColor="red" mouseDown="dragIt(event)" />
<mx:Canvas id="green" width="20" height="20"
borderStyle="solid" backgroundColor="green" mouseDown="dragIt(event)" />
<mx:Canvas id="blue" width="20" height="20"
borderStyle="solid" backgroundColor="blue" mouseDown="dragIt(event)" />
</mx:HBox>
<mx:HBox id="buyList" backgroundColor="white"
borderStyle="solid" width="100" height="100" dragEnter="dragEnter(event)" dragDrop="dragDrop(event)" />
</mx:VBox>
</mx:Application>
DragManager小应用
posted on 2010-06-15 20:44
小果子 阅读(496)
评论(0) 编辑 收藏 引用 所属分类:
Flex