How to use SmartDragManager class included in Nabiro

This is a sample application that shows you how simple is add and remove drag and drop functionalities to any DisplayObject component using Nabiro's SmartDragManager class.
Note that you need Nabiro 0.950 or major
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
creationComplete="addDrag()"
xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

<mx:Script>
<![CDATA[

import mx.events.DragEvent;
import com.gnstudio.nabiro.utilities.SmartDragManager;




private function onChange(e:Event):void{

if(e.currentTarget.selected == true){

addDrag()

}else{

removeDrag()

}

}

private function addDrag():void{

SmartDragManager.makeDraggable(myImage);//make the image on the left draggable
SmartDragManager.makeDraggable(myImage2,false);//make the image on the right draggable without the proxy image
SmartDragManager.makeDroppable(myContainer,onDrop);//make the container droppable

}

private function removeDrag():void{

SmartDragManager.removeDrag(myImage);//remove the drag
SmartDragManager.removeDrag(myImage2);//remove the drag
SmartDragManager.removeDrop(myContainer);//remove the drop

}

private function onDrop(e:DragEvent):void{

var obj:Object = e.dragSource.dataForFormat('item');

var bitmapData:BitmapData = new BitmapData(obj.width, obj.height, true, 0x00000000);
bitmapData.draw(obj as IBitmapDrawable);

var bitmap:Bitmap = new Bitmap(bitmapData);

var img:Image = new Image();
img.source = bitmap;

myContainer.addChild(img);

}

]]>
</mx:Script>


<mx:HBox horizontalCenter="0">

<mx:Image
toolTip="Drag Me"
id="myImage"
source="assets/nabiro_logo-1.png"
/>
<mx:Image
toolTip="Drag Me"
id="myImage2"
source="assets/nabiro_logo-1.png"
/>

</mx:HBox>

<mx:CheckBox
label="Enable Drag"
horizontalCenter="0"
y="130"
selected="true"
change="onChange(event)"
/>


<mx:Panel
id="myContainer"
title="Drop Nabiro logo here"
horizontalCenter="0"
y="150"
width="500"
height="250"
/>


</mx:Application>

Comments on this post

Post a comment

Embed any code between [code] [/code] tags
captcha image   Reload