flex中的拖放操作(二)
在家上网赚钱更容易
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
??????? import mx.collections.ArrayCollection;
??????? import mx.containers.Canvas;
??????? import mx.managers.DragManager;
??????? import mx.core.DragSource;
??????? import mx.events.DragEvent;
??????? private var provider:Array=new Array();
??????? private function doGrag(event:MouseEvent):void{
?????????????? var dragData:Object={"产品名称":"诺基亚7610","价格":"1650.00"};
?????????????? var ds:DragSource=new DragSource();
?????????????? ds.addData(dragData,"myDs");
?????????????? var cpyImage:Canvas=new Canvas();
?????????????? cpyImage.width=myImage.width;
?????????????? cpyImage.height=myImage.height;
?????????????? cpyImage.setStyle("backgroundImage",myImage.source);
?????????????? DragManager.doDrag(myImage,ds,event,cpyImage);????????
??????? }
??????? private function doDragEnter(event:DragEvent):void
??????? {
?????????????? if (event.dragSource.hasFormat("myDs"))
?????????????? {
????????????????????? DragManager.acceptDragDrop(myDataGrid);
?????????????? }
??????? }
??????? private function doDragDrop(event:DragEvent):void
??????? {
?????????????? var data:Object =event.dragSource.dataForFormat("myDs");
?????????????? provider.push(data);
?????????????? myDataGrid.dataProvider=provider;
??????? }
]]>
</mx:Script>
<mx:Image id="myImage" x="55" y="75" source="Nokia_7610.png" mouseMove="doGrag(event)"/>
<mx:DataGrid? id="myDataGrid" x="222" y="103" dragEnter="doDragEnter(event)" dragDrop="doDragDrop(event)"/>
</mx:Application>
?
var cpyImage:Canvas=new Canvas();
?????????????? cpyImage.width=myImage.width;
?????????????? cpyImage.height=myImage.height;
?????????????? cpyImage.setStyle("backgroundImage",myImage.source);
cpyImage是定义了一个图片的拖拽代理,将cpyimage的backgroundImage样式设置为图片的source属性,大小和图片一致。本例中用Canvas控件作为代理控件,Flex中任何可视控件都可作为代理。
?
写的不好,希望大家能看明白。
?
在家上网赚钱更容易