user2817200
user2817200

Reputation: 1117

Actionscript 3 - dropTarget not working

I have two movieclips, one called ltr and the other called ltrTarget. They both are circles beside each other. This is my code:

import flash.geom.Point;

ltr.addEventListener( MouseEvent.MOUSE_DOWN, pickup ); 
ltr.addEventListener( MouseEvent.MOUSE_UP, place );

var startingLocation = new Point();

function pickup( evt:MouseEvent ):void {
    startingLocation.x = evt.target.x;
    startingLocation.y = evt.target.y;
    evt.target.startDrag();
}

function place( evt:MouseEvent ):void {
      evt.target.stopDrag();
      trace(evt.target.dropTarget);

      if ( evt.target.dropTarget == ltrTarget ) {
          evt.target.x = ltrTarget.x;
          evt.target.y = ltrTarget.y;

      } else {
          evt.target.x = startingLocation.x;
          evt.target.y = startingLocation.y;
      }     
}

Now, when I drap ltr and drop it on a place other than ltrTarget, it traces 'null' and resets to its original location (resets to startingLocation), which is correct. However, when I drop it on top of ltrTarget, it traces '[object Shape]' but it still resets back to startingLocation rather than taking ltrTarget's x and y position.

I changed

trace(evt.target.dropTarget);

to

trace(evt.target.dropTarget.name);

and when I place it no top of ltrTarget, it traces 'instance1'. How come ltr's x and y position does not become ltrTarget's x and y position when I drop ltr on top of ltrTarget?

Upvotes: 0

Views: 753

Answers (1)

M4tchB0X3r
M4tchB0X3r

Reputation: 1531

Use event.currentTarget ... or even the direct instance .. ltr

Upvotes: 1

Related Questions