我正在学习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;
}
}
}
答案 0 :(得分:0)
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;
}
}
}