Flash AS3-单击按钮后,使其停留在“中”;超过;模式

Flash AS3-单击按钮后,使其停留在“中”;超过;模式,flash,actionscript-3,button,state,Flash,Actionscript 3,Button,State,我该怎么做 我有树钮扣。一次只能“选择”一个。他们播放不同的动画 我需要的是将按钮(根据其“过”、“上”和“下”状态的不同,具有不同的bg颜色)设置为“下”状态 简而言之;我需要在按下按钮时将其冻结在关闭状态。 当我点击其他按钮时,它应该会回到正常状态,新按钮会被冻结在关闭状态 我用的是Flash,AS3 谢谢!=) 试试我根据您链接的解决方案改编的代码 private toggledButton:SimpleButton; private function buttonToggle(butt

我该怎么做

我有树钮扣。一次只能“选择”一个。他们播放不同的动画

我需要的是将按钮(根据其“过”、“上”和“下”状态的不同,具有不同的bg颜色)设置为“下”状态

简而言之;我需要在按下按钮时将其冻结在关闭状态。 当我点击其他按钮时,它应该会回到正常状态,新按钮会被冻结在关闭状态

我用的是Flash,AS3


谢谢!=)

试试我根据您链接的解决方案改编的代码

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;
    }
}

请尝试我根据您链接的解决方案改编的代码

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;
    }
}
简单地说:

如果将“上状态=下状态”设置为显示某个项目已被选中,则无法返回到原始上状态。因此,将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;
完成,代码最少。

简单说明:

如果将“上状态=下状态”设置为显示某个项目已被选中,则无法返回到原始上状态。因此,将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;

完成,代码最少。

找到此。。但是,当我按下一个新按钮时,如何将状态交换回来呢?我只是将每个状态存储在init();并在每次单击按钮时清除切换。。(还不能回答我自己的问题。)似乎最简单的事情就是重新制作一个单选按钮组件。找到这个。。但是,当我按下一个新按钮时,如何将状态交换回来呢?我只是将每个状态存储在init();并在每次单击按钮时清除切换。。(还不能回答我自己的问题。)看起来最简单的事情就是重新制作一个单选按钮组件