我hacktastic解决方法是使用SimpleButton的保持,但覆盖的状态变化。我把北部,夸大和唐斯泰特相同的容器精灵,然后侦听鼠标上/上/下/并在合适的时间插入显示对象我想要到该容器中。它不像一个固定的解决方案,但它适用于我的目的。
我的简化代码:
public class ButtonController
{
protected var button:SimpleButton;
protected var container:Sprite;
protected var upState:DisplayObject;
protected var overState:DisplayObject;
protected var downState:DisplayObject;
public function ButtonController(button:SimpleButton) {
this.button = button;
upState = button.upState;
overState = button.overState;
downState = button.downState;
container = new Sprite();
button.upState = container;
button.overState = container;
button.downState = container;
container.addChild(upState);
button.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
button.addEventListener(MouseEvent.MOUSE_UP, mouseUp);
button.addEventListener(MouseEvent.ROLL_OVER, mouseOver);
button.addEventListener(MouseEvent.ROLL_OUT, mouseOut);
}
protected function mouseDown(...ig):void {
container.removeChildAt(0);
container.addChild(downState);
}
protected function mouseUp(...ig):void {
container.removeChildAt(0);
container.addChild(overState);
}
protected function mouseOver(...ig):void {
container.removeChildAt(0);
container.addChild(overState);
}
protected function mouseOut(...ig):void {
container.removeChildAt(0);
container.addChild(upState);
}
}
这种方法的鼠标悬停视觉效果出现之前增加了一个轻微的延迟。在传统的SimpleButton中,mouseover状态发生变化,然后在触发mouseover事件之前等待一帧。所以现在状态改变发生在一帧之后。 – 2012-08-10 23:04:06