Note that there are some explanatory texts on larger screens.

plurals
  1. POActionscript 3.0 dragging one MovieClip at a time
    primarykey
    data
    text
    <p>I have been creating a Flash file where more than one MovieClip can be dragged and moved around the stage. I have set up functions up to control when it is being dragged but when I click on one MovieClip the other instantly attaches itself to the other. How do I get around this?</p> <p>Here is the code:</p> <pre><code>import flash.geom.Point; //Add variables and items, such as milk and eggs to stage: var milkClickOffset:Point = null; var eggClickOffset:Point = null; var milk:Milk = new Milk(); milk.x = 250; milk.y = 250; addChild(milk); var egg:Egg = new Egg(); egg.x = 330; egg.y = 330; addChild(egg); //Milk Event listeners:; addEventListener(MouseEvent.MOUSE_DOWN, startMilkDrag); addEventListener(MouseEvent.MOUSE_UP, stopMilkDrag); addEventListener(Event.ENTER_FRAME, dragMilk); //Egg Event listeners: addEventListener(MouseEvent.MOUSE_DOWN, startEggDrag); addEventListener(MouseEvent.MOUSE_UP, stopEggDrag); addEventListener(Event.ENTER_FRAME, dragEgg); //Milk Functions:; function startMilkDrag(event:MouseEvent):void { milkClickOffset = new Point(event.localX,event.localY); } function stopMilkDrag(event:MouseEvent):void { milkClickOffset = null; } function dragMilk(event:Event):void { if (milkClickOffset != null) {// must be dragging milk.x = mouseX - milkClickOffset.x; milk.y = mouseY - milkClickOffset.y; } } //Egg Functions: function startEggDrag(event:MouseEvent):void { eggClickOffset = new Point(event.localX,event.localY); } function stopEggDrag(event:MouseEvent):void { eggClickOffset = null; } function dragEgg(event:Event):void { if (eggClickOffset != null) {// must be dragging egg.x = mouseX - eggClickOffset.x; egg.y = mouseY - eggClickOffset.y; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload