AS3 Click-and-Rotate Content


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

This code is taken from David Stiller's post on the CommunityMX website. All credit goes to him.


Copy this code and paste it in your HTML
  1. photos.stop();
  2.  
  3. var startX:Number;
  4. var startFrame:int;
  5. var changeDistance:int;
  6. var travelDistance:int;
  7.  
  8. photos.buttonMode = true;
  9. photos.addEventListener(MouseEvent.MOUSE_DOWN, pressHandler);
  10.  
  11. function pressHandler(evt:MouseEvent):void {
  12. startX = photos.mouseX;
  13. startFrame = photos.currentFrame;
  14. photos.addEventListener(MouseEvent.MOUSE_MOVE, moveHandler);
  15. stage.addEventListener(MouseEvent.MOUSE_UP, releaseHandler);
  16. }
  17.  
  18. function releaseHandler(evt:MouseEvent):void {
  19. photos.removeEventListener(MouseEvent.MOUSE_MOVE, moveHandler);
  20. stage.removeEventListener(MouseEvent.MOUSE_UP, releaseHandler);
  21. }
  22.  
  23. function moveHandler(evt:MouseEvent):void {
  24. changeDistance = Math.round((photos.mouseX - startX) / 10);
  25. travelDistance = startFrame + changeDistance;
  26. if (travelDistance > photos.totalFrames) {
  27. photos.gotoAndStop(travelDistance % photos.totalFrames);
  28. } else if (travelDistance < 0) {
  29. photos.gotoAndStop(photos.totalFrames + (travelDistance % photos.totalFrames));
  30. } else {
  31. photos.gotoAndStop(travelDistance);
  32. }
  33. }

URL: http://www.communitymx.com/content/article.cfm?cid=8F0CA

Report this snippet


Comments


You need to login to view comments.