无法停止齿轮旋转
Can't Stop a Gear Rotation
我是 AS3 编程的新手。我想问一下如何停止这个齿轮动画。我只是做了一个停止旋转的函数,但事件不会停止。
import flash.events.MouseEvent;
var smallGearSpeed:Number = -2;
var bigGearSpeed:Number = 1;
btn_Normal.addEventListener(MouseEvent.CLICK, fl_rotateNormalHandler);
btn_Acc.addEventListener(MouseEvent.CLICK, fl_rotateAccHandler);
btn_Stop.addEventListener(MouseEvent.CLICK, fl_rotateStopHandler);
function fl_rotateStopHandler (evt:MouseEvent):void {
addEventListener(Event.ENTER_FRAME, fl_rotateStop);
}
function fl_rotateNormalHandler (evt:MouseEvent):void {
addEventListener(Event.ENTER_FRAME, fl_rotateNormal);
}
function fl_rotateAccHandler(evt:MouseEvent):void {
addEventListener(Event.ENTER_FRAME, fl_rotateAcc);
}
function fl_rotateNormal (evt:Event):void {
rotateNormal();
}
function fl_rotateAcc (evt:Event):void {
rotateAcc();
}
function fl_rotateStop (evt:Event):void {
rotateStop();
}
function rotateNormal():void {
mc_BigGear.rotation += bigGearSpeed;
mc_SmallGear.rotation += smallGearSpeed;
trace("Normal Clicked !!!");
}
function rotateAcc():void {
mc_BigGear.rotation += bigGearSpeed;
bigGearSpeed = bigGearSpeed + .1;
mc_SmallGear.rotation += smallGearSpeed;
smallGearSpeed = smallGearSpeed - .1;
trace("Accelerate Clicked !!!");
}
function rotateStop():void {
mc_BigGear.rotation = bigGearSpeed - 1;
mc_SmallGear.rotation = smallGearSpeed + 2;
trace("Stop Clicked !!!");
}
希望有人能帮我解决这个问题。抱歉我的英语不好,谢谢你:)
对于 "stop" 事件,删除您之前添加的侦听器,例如:
removeEventListener(Event.ENTER_FRAME, fl_rotateNormal);
我是 AS3 编程的新手。我想问一下如何停止这个齿轮动画。我只是做了一个停止旋转的函数,但事件不会停止。
import flash.events.MouseEvent;
var smallGearSpeed:Number = -2;
var bigGearSpeed:Number = 1;
btn_Normal.addEventListener(MouseEvent.CLICK, fl_rotateNormalHandler);
btn_Acc.addEventListener(MouseEvent.CLICK, fl_rotateAccHandler);
btn_Stop.addEventListener(MouseEvent.CLICK, fl_rotateStopHandler);
function fl_rotateStopHandler (evt:MouseEvent):void {
addEventListener(Event.ENTER_FRAME, fl_rotateStop);
}
function fl_rotateNormalHandler (evt:MouseEvent):void {
addEventListener(Event.ENTER_FRAME, fl_rotateNormal);
}
function fl_rotateAccHandler(evt:MouseEvent):void {
addEventListener(Event.ENTER_FRAME, fl_rotateAcc);
}
function fl_rotateNormal (evt:Event):void {
rotateNormal();
}
function fl_rotateAcc (evt:Event):void {
rotateAcc();
}
function fl_rotateStop (evt:Event):void {
rotateStop();
}
function rotateNormal():void {
mc_BigGear.rotation += bigGearSpeed;
mc_SmallGear.rotation += smallGearSpeed;
trace("Normal Clicked !!!");
}
function rotateAcc():void {
mc_BigGear.rotation += bigGearSpeed;
bigGearSpeed = bigGearSpeed + .1;
mc_SmallGear.rotation += smallGearSpeed;
smallGearSpeed = smallGearSpeed - .1;
trace("Accelerate Clicked !!!");
}
function rotateStop():void {
mc_BigGear.rotation = bigGearSpeed - 1;
mc_SmallGear.rotation = smallGearSpeed + 2;
trace("Stop Clicked !!!");
}
希望有人能帮我解决这个问题。抱歉我的英语不好,谢谢你:)
对于 "stop" 事件,删除您之前添加的侦听器,例如:
removeEventListener(Event.ENTER_FRAME, fl_rotateNormal);