Skip to main content
Participating Frequently
March 17, 2010
Answered

Issue with mouse_up and mouse_down actions

  • March 17, 2010
  • 1 reply
  • 979 views

Hello,

I placed this code in the actionscript so i could drag and drop the mucles and place them into their targets. My issue is that once the mouse is down on the muscle "temporalis", the temporalis muscle lifts up but does not drop it when the mouse is up. I set functions for drop it and pick up when the mouse is down and when the mouse is up. Also I set the pick up to be true so the temporalis muscle is picked up from the middle, but it is not picking up from the middle. I dont see anything wrong with my code can someone please help? Here is the Code:

1     temporalis_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
2     temporalis_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);

3    

4     function pickUp(event:MouseEvent):void {
5           event.target.startDrag(true);
6     }
7     function dropIt(event:MouseEvent):void {
8          event.target.stopDrag();
9     }

10

11     temporalis_mc.buttonMode = true;

Thanks,

A Student.

This topic has been closed for replies.
Correct answer kglad

use:


1     temporalis_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
2

3    

4     function pickUp(event:MouseEvent):void {
5           event.target.startDrag(true);

stage.addEventListener(MouseEvent.MOUSE_UP, dropIt);


6     }
7     function dropIt(event:MouseEvent):void {
8          stopDrag();


stage.removeEventListener(MouseEvent.MOUSE_UP, dropIt);



9     }


10


11     temporalis_mc.buttonMode = true;




1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
March 17, 2010

use:


1     temporalis_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
2

3    

4     function pickUp(event:MouseEvent):void {
5           event.target.startDrag(true);

stage.addEventListener(MouseEvent.MOUSE_UP, dropIt);


6     }
7     function dropIt(event:MouseEvent):void {
8          stopDrag();


stage.removeEventListener(MouseEvent.MOUSE_UP, dropIt);



9     }


10


11     temporalis_mc.buttonMode = true;




Participating Frequently
March 18, 2010

I tried replacing the text target with currentTarget, and it still does not

drag from the center, but it does let go when I lift the mouse(Thank You!). However, I noticed that there is a crosshair in the corner of the box

that outlines the symbol when its selected. Could this be why the object is

not dragging from the center, and why my functions will not work?

kglad
Community Expert
Community Expert
March 18, 2010

lockcenter should really be called lockregistrationpoint.  so, if your reg pt is the upper left, that where's the startDrag() will lock.