我的 hacktastic 解决方法是继续使用 SimpleButton 但覆盖状态更改。我将 upState、overState 和 downState 设置为同一个容器精灵,然后监听鼠标上/下/下/出,并在正确的时间将我想要的显示对象插入到该容器中。它感觉不是一个可靠的解决方案,但它适用于我的目的。
我的简化代码:
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);
}
}