【问题标题】:AS3 - After clicking button, make it stay in "over" modeAS3 - 单击按钮后,使其保持“结束”模式
【发布时间】:2012-02-22 11:44:32
【问题描述】:

我该怎么做?

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

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

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

我正在使用 Flash、AS3..

谢谢! =)

【问题讨论】:

  • 但是当我点击一个新按钮时如何交换状态?
  • 我只是将每个状态存储在 init();并在每次单击按钮时清除切换..(还不能回答我自己的问题..:P)
  • 似乎最简单的事情就是重新设置 RadioButton 组件

标签: flash actionscript-3 button state


【解决方案1】:

简单地说:

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

用最少的代码完成。

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:
      private function onClick(event:MouseEvent):void {
          if(prevSelected) {
              //change the skin of selected 
          }
          //save the current selected button 
          //change the current selected button skin
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-04-09
        • 2015-09-19
        • 1970-01-01
        • 2020-04-25
        • 2019-10-04
        • 1970-01-01
        • 1970-01-01
        • 2020-02-01
        相关资源
        最近更新 更多