【问题标题】:Can't Stop a Gear Rotation无法停止齿轮旋转
【发布时间】:2015-06-15 01:14:12
【问题描述】:

我是 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 !!!");

    }

我希望有人能帮我解决这个问题。对不起我的英语不好,谢谢:)

【问题讨论】:

    标签: actionscript-3 animation event-handling


    【解决方案1】:

    要“停止”事件,请移除您之前添加的侦听器,例如:

    removeEventListener(Event.ENTER_FRAME, fl_rotateNormal);
    

    【讨论】:

    • 非常感谢您解决了我的问题,它的工作! :)
    猜你喜欢
    • 2019-06-24
    • 1970-01-01
    • 1970-01-01
    • 2018-10-24
    • 1970-01-01
    • 1970-01-01
    • 2012-01-05
    • 2012-03-27
    • 1970-01-01
    相关资源
    最近更新 更多