用于as3的扩展类中的ENTER_FRAME监听器

时间:2009-08-27 23:34:11

标签: flash actionscript-3 class

我正在学习AS3的基础知识,并且正在学习一本教程。我们刚刚创建了一个类,当链接到电影剪辑(或者可以想象任何精灵)时,当将鼠标滚过它们时会放大它们。为了确保我记住了所有的原则,我试着创建一个类,当它被鼠标悬停时会使sprite旋转,并在我推出时停止,但是我很难让ENTER_FRAME监听器发挥得很好。知道我哪里错了吗?

包 {     import flash.display.Sprite;     import flash.events.MouseEvent;     import flash.events.Event;

public class Spinnah extends Sprite
{
    private var _origRotation:Number;

    public function Spinnah()
    {
        _origRotation = this.rotation;
        this.addEventListener(MouseEvent.ROLL_OVER, eFrameOn);
        this.addEventListener(MouseEvent.ROLL_OUT, stopSpin);
    }

    private function eFrameOn (Event:MouseEvent):void
    {
        stage.addEventListener(Event.ENTER_FRAME, spin);
    }

    private function spin (event:Event):void
    {
        this.rotation += 1;
    }

    private function stopSpin (event:Event):void
    {
        stage.removeEventListener(Event.ENTER_FRAME, spin);
        this.rotation = _origRotation;
    }
}

}

1 个答案:

答案 0 :(得分:0)

哇,没关系。我是个白痴。我正在使ROLL_OUT函数使用错误的侦听器,并且在大小写中出现了一些错误。抱歉。为了存档,这是工作代码。

package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.Event;

public class Spinnah extends Sprite
{
    private var _origRotation:Number;

    public function Spinnah()
    {
        _origRotation = this.rotation;
        this.addEventListener(MouseEvent.ROLL_OVER, eFrameOn);
        this.addEventListener(MouseEvent.ROLL_OUT, stopSpin);
    }

    private function eFrameOn (event:MouseEvent):void
    {
        stage.addEventListener(Event.ENTER_FRAME, spin);
    }

    private function spin (event:Event):void
    {
        this.rotation += 1;
    }

    private function stopSpin (event:MouseEvent):void
    {
        stage.removeEventListener(Event.ENTER_FRAME, spin);
        this.rotation = _origRotation;
    }
}

}