简体   繁体   English

Flex:在每种状态下更改“启用/禁用”按钮的样式

[英]Flex : Change the Style of Enabled/Disabled button in each state

I have a specific button that included to some states. 我有一个包含某些状态的特定按钮。 I must make it disabled or enabled inside of those states. 我必须在这些状态下将其禁用或启用。

But it's not problem. 但这不是问题。 Actually the problem is: I have 2 different style classes and I want assign each one of them to enabled or disabled of button, inside the active state. 实际的问题是:我有2个不同的样式类,我想将它们中的每个样式类分配给处于活动状态的启用或禁用按钮。

So I must inside the active state check if now the button is enabled assign the [for example] .red style class to it and if it's disable, assign the .blue style class. 因此,我必须在活动状态内检查是否已启用按钮,然后为它分配[例如] .red样式类,如果已禁用,则分配.blue样式类。

How can I do it? 我该怎么做? Thanks in advance... 提前致谢...

You should be able to use the dot notationin MXML to accomplish this: 您应该能够在MXML中使用点符号来完成此操作:

<s:Button styleNanem.state1 ="red" styleName.state2="blue" />

I'm pretty sure this syntax was introduced in Flex 4. 我非常确定Flex 4中引入了此语法。


If you need to change the button's state whenever the enabled property is changed, you can loop this up in a function: 如果您每当更改enabled属性时都需要更改按钮的状态,则可以在函数中进行循环:

protected function changeButtonState(enabledValue:Boolean, styleName:String):void{
 this.button.enabled = enabledvalue;
 this.button.styleName = styleName;
}

Instead of setting the enabled property directly, use the above method; 使用上面的方法,而不是直接设置enabled属性。 and you can determine the styleName based on the state. 然后您可以根据状态确定styleName。


Third update in response to comments on this post 第三次更新以回应对此帖子的评论

Almost Every property in the Flex Framework classes dispatches a propertyChanged event when the property changes. 当属性更改时,Flex Framework类中的几乎每个属性都会调度一个propertyChanged事件。 So, you can listen, on the button, to the enabledChanged event. 因此,您可以在按钮上侦听enabledChanged事件。 The metadata isn't set up so you'll have to add the event listener in ActionScript: 元数据未设置,因此您必须在ActionScript中添加事件侦听器:

button.addEventListener('enabledChanged',onEnabledChanged);

protected function onEnabledChanged(event:Event):void{
  if(currentState = 'state1'){
    if(button.enabled){
      button.styleName = 'blue';
    } else {
      button.styleName = 'red';
    }
  } else if (currentState = 'state2'){
    if(button.enabled){
      button.styleName = 'green';
    } else {
      button.styleName = 'orange';
    }

  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM