应用思考-教育技术论坛

标题: 如何实现拖动图形时实现旋转功能 [打印本页]

作者: 馒头    时间: 2012-4-21 15:21
标题: 如何实现拖动图形时实现旋转功能
我想做一个七巧板拼图的课件,拖拽部分会做,不会让拖拽的图形旋转,想请教高手指点迷津!


作者: etthink    时间: 2012-4-22 10:45
附群中朋友提供的解决方法:
(, 下载次数: 85)

  1. var p:Number = Math.PI / 180;
  2. var dx:Number;
  3. var dy:Number;
  4. var angle:Number;

  5. var spr:Sprite=addChild(new Sprite())as Sprite;
  6. spr.x = 275;
  7. spr.y = 200;
  8. var rect_mc:MovieClip=spr.addChild(new MovieClip())as MovieClip;
  9. var circle_mc:MovieClip=spr.addChild(new MovieClip())as MovieClip;
  10. rect_mc.graphics.beginFill (0xff00ff,1);
  11. rect_mc.graphics.drawRect (-100,-50,200,100);
  12. rect_mc.graphics.endFill ();
  13. circle_mc.graphics.beginFill (0x000000,1);
  14. circle_mc.graphics.drawCircle (0,0,6);
  15. circle_mc.graphics.endFill ();
  16. circle_mc.alpha = 0;

  17. rect_mc.addEventListener (MouseEvent.MOUSE_OVER,overHandler);
  18. rect_mc.addEventListener (MouseEvent.MOUSE_OUT,outHandler);
  19. rect_mc.addEventListener (MouseEvent.MOUSE_DOWN,downHandler);


  20. function overHandler (e)
  21. {
  22. circle_mc.alpha = 1;

  23. }
  24. function outHandler (e)
  25. {
  26. circle_mc.alpha = 0;
  27. }
  28. function downHandler (e)
  29. {
  30. spr.startDrag ();
  31. stage.addEventListener (MouseEvent.MOUSE_UP,upHandler);

  32. }
  33. function upHandler (e)
  34. {
  35. spr.stopDrag ();
  36. spr.removeEventListener (MouseEvent.MOUSE_MOVE,sprMove);
  37. }

  38. circle_mc.addEventListener (MouseEvent.MOUSE_OVER,circleOver);
  39. function circleOver (e)
  40. {
  41. circle_mc.alpha = 1;
  42. circle_mc.addEventListener (MouseEvent.MOUSE_DOWN,sprDown);
  43. }
  44. function sprDown (e)
  45. {
  46. spr.addEventListener (MouseEvent.MOUSE_MOVE,sprMove);
  47. stage.addEventListener (MouseEvent.MOUSE_UP,upHandler);
  48. }
  49. function sprMove (e)
  50. {
  51. dx = mouseX - spr.x;
  52. dy = mouseY - spr.y;
  53. angle = Math.atan2(dy,dx) / p;
  54. spr.rotation = angle;
  55. }
复制代码








欢迎光临 应用思考-教育技术论坛 (http://etthink.com/) Powered by Discuz! X3.4