AS3 - 单击按钮后,使其保持在“结束”状态模式

发布于 2025-01-08 04:19:56 字数 212 浏览 0 评论 0原文

我该怎么做?

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

我需要的是将按钮(根据其结束、向上和向下状态具有不同的背景颜色)设置为向下状态。

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

我正在使用 Flash、AS3..

谢谢! =)

How would I do this?

I've got tree buttons. Only one is supposed to be "selected" at a time. They play different animations.

What I need, is to set the button (which has different bg color depending on its over, up and down state) to it's down state.

Simply put; I need to freeze the button in it's down-state when it's clicked.
And when I click one of the other buttons, it's supposed to return back to its normal state, and the new button is to be frozen in it's down state.

I'm using Flash, AS3..

Thanks! =)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

白云不回头 2025-01-15 04:19:56

简单地说:

当你设置 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;

完成,用最少的代码。

Simply stated:

When you set the upState = downState to show that an item was selected, you have lost the ability to go back to the original upState. So it's a very simple matter to store the upState as a variable so that you can ALWAYS go back to it.

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

Done, with minimal code.

薄荷港 2025-01-15 04:19:56

尝试一下我根据您链接到的解决方案改编的代码。

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

Try this code that I adapted from the solution you linked to.

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;
    }
}
与君绝 2025-01-15 04:19:56
private function onClick(event:MouseEvent):void {
    if(prevSelected) {
        //change the skin of selected 
    }
    //save the current selected button 
    //change the current selected button skin
}
private function onClick(event:MouseEvent):void {
    if(prevSelected) {
        //change the skin of selected 
    }
    //save the current selected button 
    //change the current selected button skin
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文