我在舞台上安装了很多按钮。它们都是第一帧和第二帧上具有开启和关闭状态的动画片段。问题是当你快速将鼠标悬停在按钮上时,它会卡在过度状态。有什么我想念的吗?
public class SimpleRollOverButton extends MovieClip
{
private var _selected:Boolean;
public function SimpleRollOverButton()
{
// EVENTS
this.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
enable();
}
//
// PUblic functions
//
public function enable():void
{
this.selected = false;
this.gotoAndStop(1);
this.mouseEnabled = this.mouseChildren = true;
this.buttonMode = true;
}
public function disable():void
{
this.mouseEnabled = this.mouseChildren = false;
this.buttonMode = false;
}
public function onState():void
{
this.disable();
this.selected = true;
this.gotoAndStop(2);
}
public function offState():void
{
this.enable();
}
//
// Private Functions
//
protected function onClick(e:MouseEvent):void
{
onState();
}
protected function onMouseOver(e:MouseEvent):void
{
this.gotoAndStop(2);
}
protected function onMouseOut(e:MouseEvent):void
{
this.gotoAndStop(1);
}
//
// ACCESSORS
//
public function get selected():Boolean
{
return _selected;
}
public function set selected(value:Boolean):void
{
_selected = value;
}
}
答案 0 :(得分:0)
您可以向舞台或MovieClip添加一个监听器,其中包含按钮(如果它有背景,并且不透明):
stage.addEventListener(MouseEvent.ROLL_OVER, turnThemOff);
function turnThemOff(evt:MouseEvent):void {
for (var i:int=0; i<yourButtons.length; i++) yourButtons[i].gotoAndStop(1);
}
如果您将鼠标快速移离SWF电影,这可能会有所帮助:
stage.addEventListener(Event.MOUSE_LEAVE, turnThemOff);