AS3 - 单击按钮后,使其保持“超过”模式

时间:2012-02-22 11:44:32

标签: flash actionscript-3 button state

我该怎么做?

我有树按钮。一次只能选择一个。他们玩不同的动画。

我需要的是将按钮(具有不同的bg颜色,具体取决于其上,下和下状态)设置为向下状态。

简单地说;当点击按钮时,我需要将按钮冻结在它的下行状态。 当我单击其中一个按钮时,它应该返回到正常状态,并且新按钮将被冻结在它的关闭状态。

我正在使用Flash,AS3 ..

谢谢! =)

3 个答案:

答案 0 :(得分:2)

简单说明:

当您设置upState = downState以显示已选择某个项目时,您将无法返回原始upState。所以将upState存储为变量是一件非常简单的事情,这样你就可以一直回到它。

//capture upstate as a variable

var buttonUpVar:DisplayObject = button.upState;

//button stays selected or in downState when released.

button.upState = button.downState;

//deselect button by going back to original upState

button.upState = buttonUpVar;

用最少的代码完成。

答案 1 :(得分:1)

尝试使用我链接到的解决方案改编的代码。

private toggledButton:SimpleButton;

private function buttonToggle(button:SimpleButton){
    var currDown:DisplayObject = button.downState;
    button.downState = button.upState;
    button.upState = currDown;
}

private function clickEvent(e:MouseEvent){
    if (toggledButton != e.target) {
        buttonToggle(e.target);
        if (toggledButton)
            buttonToggle(toggledButton);
        toggledButton = e.target;
    }
}

答案 2 :(得分:1)

private function onClick(event:MouseEvent):void {
    if(prevSelected) {
        //change the skin of selected 
    }
    //save the current selected button 
    //change the current selected button skin
}
相关问题