附群中朋友提供的解决方法:
移动旋转.rar
(5.9 KB, 下载次数: 83)
- var p:Number = Math.PI / 180;
- var dx:Number;
- var dy:Number;
- var angle:Number;
- var spr:Sprite=addChild(new Sprite())as Sprite;
- spr.x = 275;
- spr.y = 200;
- var rect_mc:MovieClip=spr.addChild(new MovieClip())as MovieClip;
- var circle_mc:MovieClip=spr.addChild(new MovieClip())as MovieClip;
- rect_mc.graphics.beginFill (0xff00ff,1);
- rect_mc.graphics.drawRect (-100,-50,200,100);
- rect_mc.graphics.endFill ();
- circle_mc.graphics.beginFill (0x000000,1);
- circle_mc.graphics.drawCircle (0,0,6);
- circle_mc.graphics.endFill ();
- circle_mc.alpha = 0;
- rect_mc.addEventListener (MouseEvent.MOUSE_OVER,overHandler);
- rect_mc.addEventListener (MouseEvent.MOUSE_OUT,outHandler);
- rect_mc.addEventListener (MouseEvent.MOUSE_DOWN,downHandler);
- function overHandler (e)
- {
- circle_mc.alpha = 1;
- }
- function outHandler (e)
- {
- circle_mc.alpha = 0;
- }
- function downHandler (e)
- {
- spr.startDrag ();
- stage.addEventListener (MouseEvent.MOUSE_UP,upHandler);
- }
- function upHandler (e)
- {
- spr.stopDrag ();
- spr.removeEventListener (MouseEvent.MOUSE_MOVE,sprMove);
- }
- circle_mc.addEventListener (MouseEvent.MOUSE_OVER,circleOver);
- function circleOver (e)
- {
- circle_mc.alpha = 1;
- circle_mc.addEventListener (MouseEvent.MOUSE_DOWN,sprDown);
- }
- function sprDown (e)
- {
- spr.addEventListener (MouseEvent.MOUSE_MOVE,sprMove);
- stage.addEventListener (MouseEvent.MOUSE_UP,upHandler);
- }
- function sprMove (e)
- {
- dx = mouseX - spr.x;
- dy = mouseY - spr.y;
- angle = Math.atan2(dy,dx) / p;
- spr.rotation = angle;
- }
复制代码
|