Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 03-25-2006, 04:46 AM   #1
john100
Registered User
 
Join Date: Feb 2006
Posts: 22
Default Using drag drop with multiple picture inside canvas

Hi,

I am using sample code from flex 2. The sample work for one image. But If I have multiple image, I don't know how to get the reference to the selected image

private function doDragDrop(eventragEvent, target1:Canvas, format:String):void
{
//var data:Object = event.dragSource.dataForFormat('img');
//HOW TO GET THE CURRENT SELECTED IMAGE HERE
// myimg.x = target1.mouseX - xOff
// myimg.y = target1.mouseY - yOff
}

Code:
<?xml version="1.0" ?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
        <![CDATA[
            //Import classes so you don't have to use full names.
            import mx.managers.DragManager;
            import mx.core.DragSource;
            import mx.events.DragEvent;
            import flash.events.MouseEvent;
            import mx.controls.Image;
            import mx.containers.Canvas;

            //Variables used to hold the image's location
            public var xOff:Number;
            public var yOff:Number;

            // Embed icon image.
            [Embed(source='globe.jpg')]
            public var globeImage:Class;

            // Drag initiator event handler, called by             //     the image's mouseMove event.
            private function dragMe(event:MouseEvent, img1:Image,                format:String):void
            {
                var dragInitiator:Image=Image(event.currentTarget);
                var ds:DragSource = new DragSource();
                ds.addData(img1, format);                
                // The drag manager uses the image as the drag proxy
                // and sets the alpha to 100 (opaque),
                // so it appears to be dragged across the canvas.
                var imageProxy:Image = new Image();
                imageProxy.source = globeImage;
                imageProxy.height=10;
                imageProxy.width=10;
                DragManager.doDrag(dragInitiator, ds, event,                     imageProxy, 0, 0, 1.00);
            }
            
            //Function called by the canvas dragEnter event; enables dropping
            private function doDragEnter(event:DragEvent):void
            {
                DragManager.acceptDragDrop(Canvas(event.target));
            }

            // Function called by the canvas dragDrop event; 
            // Sets the image object's position, 
            // "dropping" it in its new location.
            private function doDragDrop(event:DragEvent,                 target1:Canvas, format:String):void
            {
                //var data:Object = event.dragSource.dataForFormat('img');
               //HOW TO GET THE CURRENT SELECTED IMAGE HERE
               // myimg.x = target1.mouseX - xOff
               // myimg.y = target1.mouseY - yOff    
            }

            // Helper function called by the dragged image's mouseMove event,
            // as the image drags across the canvas.
            // The function updates the xOff and yOff variables to show the
            // current mouse location.    
            private function myoffset(img:Image):void {
                xOff = img.mouseX
                yOff = img.mouseY
            }        
        ]]>
    </mx:Script>
    
    <!-- The Canvas is both the drag target --> 
    <mx:Canvas id="v1" width="500" height="500" dragEnter="doDragEnter(event)" 
        dragDrop ="doDragDrop(event, v1, 'img')" borderStyle="solid" 
        backgroundColor="#DDDDDD">
    <!-- The image is the drag initiator and the drag proxy. -->
        <mx:Image id="myimg1" source="@Embed(source='globe.jpg')" 
            mouseMove="dragMe(event, myimg1, 'img');myoffset(myimg1);"/> 
        <mx:Image id="myimg2" source="@Embed(source='globe.jpg')" 
            mouseMove="dragMe(event, myimg2, 'img');myoffset(myimg2);"/> 
        <mx:Image id="myimg3" source="@Embed(source='globe.jpg')" 
            mouseMove="dragMe(event, myimg3, 'img');myoffset(myimg3);"/>                         
    </mx:Canvas>
</mx:Application>
john100 is offline   Reply With Quote
Old 03-25-2006, 04:57 AM   #2
john100
Registered User
 
Join Date: Feb 2006
Posts: 22
Default

I found out the solution after spending one hour reading.

private function doDragDrop(eventragEvent, target1:Canvas, format:String):void
{
var data:Object = event.dragSource.dataForFormat('img');

data.x = target1.mouseX - xOff
data.y = target1.mouseY - yOff
}
john100 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Drag & drop picklejar ActionScript 2.0 0 02-27-2006 02:27 PM
buttons in drag & drop map nzassenhaus Flash 8 General Questions 1 12-09-2005 04:52 PM
Drag and Drop 3 items on 3 hit states... then you can continue yinyang042 ActionScript 1.0 (and below) 3 10-26-2005 09:10 PM
random drag and drop nicky ActionScript 1.0 (and below) 10 08-02-2004 10:23 AM
drag and drop to any drop target rossbruniges ActionScript 2.0 4 06-18-2004 06:14 AM


All times are GMT. The time now is 01:47 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.