2011年1月17日 星期一

[AS3] 因應滑鼠指標mouseX位於stage中線的右或左,使目標實體循Y軸 Tweener 旋轉至特定角度

1000117_DisplayObject__mouseX_rotationY_1.swf




import flash.ui.Mouse;
import flash.events.MouseEvent;
import caurina.transitions.Tweener;
//
var flag:int;
//
plane.x = stage.stageWidth/2;
plane.y = stage.stageHeight/2;
//
this.addEventListener(MouseEvent.MOUSE_MOVE, rotateZ);
this.addEventListener(MouseEvent.ROLL_OUT, zeroY);
//
function rotateZ(e:MouseEvent):void{
 var keyX:Number = stage.stageWidth/2;
 if(mouseX > keyX){
  flag = 1;
  //plane.rotationY = 30;
  rotateTween();
 }else if(mouseX < keyX){
  flag = -1;
  //plane.rotationY = -30;
  rotateTween();
 }
}
//
function rotateTween():void{
 Tweener.addTween(plane, {
  rotationY :flag*30,
  time :1.2
 });
}
//
function zeroY(e:MouseEvent):void{
 Tweener.addTween(plane, {
  rotationY :0,
  time :1
 });
}

沒有留言: