check out!!
give the image
customise more by giving the border to images
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:HBox x="10" y="0" width="759" height="108" borderStyle="solid"
borderThickness="3" borderColor="#1396F2"
creationComplete="addImage(event,true)"
dragDrop="{dragDropHandler(event);}" dragEnter="{dragEnterHandler(event);}"
backgroundColor="#F68B8B">
</mx:HBox>
<mx:Script>
<![CDATA[
import mx.core.UIComponent;
import mx.containers.Canvas;
import mx.controls.Alert;
import mx.events.DragEvent;
import mx.managers.DragManager;
import mx.core.DragSource;
import mx.containers.HBox;
import mx.events.FlexEvent;
import mx.controls.Image;
private var myClassFactory:ClassFactory = new ClassFactory(Image);
[Bindable][Embed(source="tmpImages/a.png")]private var i1:Class;
[Bindable][Embed(source="tmpImages/b.png")]private var i2:Class;
[Bindable][Embed(source="tmpImages/c.png")]private var i3:Class;
[Bindable][Embed(source="tmpImages/d.png")]private var i4:Class;
[Bindable][Embed(source="tmpImages/e.png")]private var i5:Class;
private function addImage(e:FlexEvent,remove:Boolean):void
{
for(var i:int=0;i<5;i++)
{
var t:Image=myClassFactory.newInstance();
t.height=80;t.width=80;
switch(i)
{
case 0:t.source=i1;break;
case 1:t.source=i2;break;
case 2:t.source=i3;break;
case 3:t.source=i4;break;
case 4:t.source=i5;break;
}
t.addEventListener(MouseEvent.MOUSE_DOWN,function(event:MouseEvent):void{dragImage(event,remove);});
(e.currentTarget as HBox).addChild(t);
}
}
public function dragImage(event:MouseEvent,remove:Boolean):void
{
var dragInitiator:Image = event.currentTarget as Image;
var ImagePath:String=dragInitiator.source as String;
var dragSource:DragSource = new DragSource();
var dragProxy:Image=new Image();
dragSource.addData(ImagePath,'ImagePath');
dragSource.addData(remove,"IsRemove");
dragProxy.height = 100 ;dragProxy.width = 100;
dragProxy.source = event.currentTarget.source;
DragManager.doDrag(dragInitiator, dragSource, event, dragProxy);
}
public function dragEnterHandler(event:DragEvent):void
{
try
{
if(event.dragSource.hasFormat("ImagePath"))
DragManager.acceptDragDrop(event.currentTarget as
UIComponent);
}catch(objError:Error)
{
Alert.show("Exception:"+objError.getStackTrace());
}
}
private function dragDropHandler(event:DragEvent):void
{
var TmpCurrentFrame:*=event.target ;
try{
if(event.dragSource.hasFormat("ImagePath"))//new Image to
be droped
{
var img:Image;
if(event.dragSource.dataForFormat("IsRemove") as
Boolean)
{ //Alert.show(" removing");
//img=event.dragInitiator as Image;
TmpCurrentFrame.addChild(event.dragInitiator as
Image);
(event.dragInitiator as Image).x=event.localX-10/2;
(event.dragInitiator as Image).y=event.localY-10/2;
}
else {Alert.show((event.dragInitiator as
Image).source as String);
img = myClassFactory.newInstance();
if(event.dragSource.dataForFormat("ImagePath")as
String==""){
img.source=(event.dragInitiator as Image).source as
String;
}else{
img.source=event.dragSource.dataForFormat("ImagePath")as String
}
img.source=(event.dragInitiator as Image).source as
String;
img.height=(event.dragInitiator as Image).height;
img.width=(event.dragInitiator as Image).width;
img.x=event.localX-10/2;
img.y=event.localY-10/2;
TmpCurrentFrame.addChild(img);
img.validateNow();
}
}
(TmpCurrentFrame as UIComponent).validateNow();
}
catch(objError:Error)
{
Alert.show("Exception:"+objError.getStackTrace());
}
}
]]>
</mx:Script>
</mx:Application>
On Fri, May 8, 2009 at 10:24 PM, <[email protected]> wrote:
> Hi Hissam,
> Can you show a sample code on this?
>
> On Fri, May 8, 2009 at 3:08 PM, HISSAM <[email protected]> wrote:
>
>> why are u using canvas, hbox
>> apply drag and drop to the images and make the drop target the hbox, then
>> when u move the images they will order them-selves
>>
>> On Thu, May 7, 2009 at 10:01 PM, priya <[email protected]> wrote:
>>
>>>
>>> Hi,
>>>
>>> I am new in flex.
>>> My problem is that i am reorder the images in canvas by move images.
>>>
>>> Plz help me.
>>>
>>> Thanks in advance.
>>>
>>>
>>>
>>
>>
>> --
>> -----------------------------
>> Regards,
>> HISSAM,
>> ------------------------------
>>
>>
>>
>>
>
>
> --
> Sincerely
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> Edwin Melendez
> Print/Web/Media
> 646-246-4368
>
>
> >
>
--
-----------------------------
Regards,
HISSAM,
------------------------------
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Flex
India Community" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/flex_india?hl=en
-~----------~----~----~----~------~----~------~--~---