Image To List

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
 <mx:Script>
  <![CDATA[
   import mx.collections.ArrayCollection;
   import mx.core.DragSource;
   import mx.managers.DragManager;
   import mx.events.DragEvent;
   import mx.core.IUIComponent;
  
   [Bindable]
   private var _Array:ArrayCollection = new ArrayCollection();
  
   private function dragIt(initiator:Image,dsData:String,event:MouseEvent, format:String):void{
      var ds:DragSource=new DragSource();
      ds.addData(dsData,format);
   var imageProxy:Image=new Image();
   imageProxy.load("dairy_milk.jpg");
   imageProxy.height=80;
   imageProxy.width=80;
      DragManager.doDrag(initiator,ds,event,imageProxy);
   }
   private function doDragEnter(event:DragEvent,format:String):void{
      if(event.dragSource.hasFormat(format)){
         DragManager.acceptDragDrop(IUIComponent(event.target));
      }
   }
   private function doDragDrop(event:DragEvent,format:String):void{
      var myLabelData:Object=new Object();
      myLabelData=event.dragSource.dataForFormat(format);
      myList.dataProvider.addItem(myLabelData);
   }
  ]]>
 </mx:Script>
 <mx:Image id="myImage" source="dairy_milk.jpg" mouseDown="dragIt(myImage,’My data here’,event,’myFormat’)"/>
 <mx:List id="myList" dataProvider="{_Array}" width="200" height="300" dragEnter="doDragEnter(event,’myFormat’)" dragDrop="doDragDrop(event,’myFormat’)" />
</mx:Application>
Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: