Drag rotate AS3


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. addEventListener(MouseEvent.CLICK, fOnEvent, false, 0, true);
  2. addEventListener(MouseEvent.MOUSE_DOWN, fOnEvent, false, 0, true);
  3. stage.addEventListener(MouseEvent.MOUSE_UP, fOnEvent, false, 0, true);
  4.  
  5. function fOnEvent(e : *) : void
  6. {
  7. var vAngle : Number;
  8.  
  9. switch (e.type)
  10. {
  11. case MouseEvent.MOUSE_DOWN:
  12. switch (e.target.name)
  13. {
  14. case "pbGrip":
  15. stage.addEventListener(MouseEvent.MOUSE_MOVE, fOnEvent, false, 0, true);
  16. break;
  17. }
  18. break;
  19. case MouseEvent.MOUSE_UP:
  20. stage.removeEventListener(MouseEvent.MOUSE_MOVE, fOnEvent);
  21. break;
  22. case MouseEvent.MOUSE_MOVE:
  23. vAngle = Math.atan2(mouseY - mcHandle.y, mouseX - mcHandle.x);
  24. mcHandle.rotation = vAngle * 180 / Math.PI;
  25. e.updateAfterEvent();
  26. break;
  27. }
  28. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.