简体   繁体   中英

ENTER_FRAME listener in extended classes for as3

I'm working on learning the basics of AS3 and have been working through a tutorial book. We just made a class that, when linked to movie clips (or conceivably any sprite) would enlarge them when rolling the mouse over them. To make sure I remembered all the principles, I tried to make a class that would make the sprite spin when moused over it, and stop when I rolled out, however I'm having trouble making the ENTER_FRAME listener play nicely. Any idea where I'm going wrong?

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:Event):void
    {
        stage.removeEventListener(Event.ENTER_FRAME, spin);
        this.rotation = _origRotation;
    }
}

}

wow, nevermind. I'm an idiot. I was making the ROLL_OUT function use the wrong listener, and had some errors in capitalization. Sorry. For the sake of the archives, here's working code.

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;
    }
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM