borna
borna

Reputation: 283

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.

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.

How can I do it? Thanks in advance...

Upvotes: 2

Views: 2378

Answers (1)

JeffryHouser
JeffryHouser

Reputation: 39408

You should be able to use the dot notationin MXML to accomplish this:

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

I'm pretty sure this syntax was introduced in 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:

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; and you can determine the styleName based on the state.


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. So, you can listen, on the button, to the enabledChanged event. The metadata isn't set up so you'll have to add the event listener in 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';
    }

  }
}

Upvotes: 1

Related Questions