Posted By

chrisaiv on 02/12/08


Tagged

as3 onReleaseOutside onDragOver onDragOut


Versions (?)

Who likes this?

8 people have marked this snippet as a favorite

shoffa
outbox
lzyy
THEPWN3R
akashaman
ssolen
tspitzr
christowiz


AS3: onDragOver, onDragOut, onReleaseOutside


 / Published in: ActionScript 3
 

URL: http://www.scottgmorgan.com/blog/index.php/2007/12/20/ondragover-ondragout-and-onreleaseoutside-in-as3/

Scott Morgan figured out a beautiful way to offer the AS2 Mouse Event onReleaseOutside.

  1. var button:Sprite = new Sprite();
  2. button.graphics.beginFill(0x000000, 1);
  3. button.graphics.drawRect(50,50,200,100);
  4. button.buttonMode = true;
  5. button.addEventListener(MouseEvent.MOUSE_DOWN, buttonPress);
  6. button.addEventListener(MouseEvent.MOUSE_UP, buttonRelease);
  7. button.addEventListener(MouseEvent.MOUSE_OVER, buttonOver);
  8. button.addEventListener(MouseEvent.MOUSE_OUT, buttonOut);
  9. addChild(button);
  10.  
  11.  
  12. function buttonPress(e:MouseEvent):void {
  13. trace(e.currentTarget.parent.parent + " == " + stage);
  14. stage.addEventListener(MouseEvent.MOUSE_UP, buttonRelease);
  15. }
  16.  
  17. function buttonRelease(e:MouseEvent):void {
  18. //Remove the Stage listener created on buttonPress
  19. stage.removeEventListener(MouseEvent.MOUSE_UP, buttonRelease);
  20.  
  21. //The Mouse was released outside the target Box
  22. if (e.currentTarget != button) {
  23. trace('onReleasedOutside');
  24. } else {
  25. //The Mouse was released inside the target Box
  26. trace('onRelease');
  27. }
  28. }
  29.  
  30. function buttonOver(e:MouseEvent):void {
  31. //The user is dragging something to the target object
  32. if (e.buttonDown) {
  33. //The state is MOUSE_DOWN
  34. trace('onDragOver');
  35. } else {
  36. //The state is MOUSE_UP
  37. trace('onRollOver');
  38. }
  39. }
  40.  
  41. function buttonOut(e:MouseEvent):void {
  42. //The user is dragging something from the target object
  43. if (e.buttonDown) {
  44. //The state is MOUSE_DOWN
  45. trace('onDragOut');
  46. } else {
  47. //The state is MOUSE_UP
  48. trace('onRollOut');
  49. }
  50. }

Report this snippet  

You need to login to post a comment.