Posted By

_mantra on 07/01/10


Tagged

actionscript as3


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

mdavidwalker
jondiscipulo


actionscript 3 simple drag and drop


 / Published in: ActionScript 3
 

simple drag and drop of an object on to a target. It will trace a 'success' message when the object is placed on the target item after being dragged and released.

  1. dragItem_mc.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
  2. dragItem_mc.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
  3.  
  4. function mouseDownHandler(e:MouseEvent):void {
  5. var obj = e.target;
  6. obj.startDrag();
  7. }
  8.  
  9. function mouseUpHandler(e:MouseEvent):void {
  10.  
  11. var obj = e.target;
  12. var target = obj.dropTarget;
  13.  
  14. if(target != null && target.parent == dropTarget_mc) {
  15.  
  16. trace('target hit');
  17. }
  18. obj.stopDrag();
  19. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: burnandbass on February 12, 2012

You better assign the MOUSE_UP listener to the stage, sometimes the mouse can be outside the dragged object

You need to login to post a comment.