views:

37

answers:

2

In mxml you declare states like this:

<box:states>
    <s:State name="active"/>
    <s:State name="disabled"/>
</box:states>

How do you acheive the same in an ActionScript class? Apparently it's the same in Flex 3 and Flex 4, whatever it is.

+2  A: 

If you can avoid it, do!

That said, hold your breath!

That said, take a look at the State Class. Create a new instance and define the overrides. I believe all the overrides are link in the "see also" link.

Each component has a "states" array.

So, just create the states manually. Add the relevant overrides, and add that state to the states array.

It isn't hard, but it can be pretty tedious. I did this for the Flextras Calendar.

www.Flextras.com
+1 You beat me to it ;)
Wade Mueller
@Wade Mueller Thanks! I think we're trading for a lot of the questions lately.
www.Flextras.com
Thanks yeah it worked, it turned out that I was totally confused between view states and skin states. They don't exactly make the difference clear in tutorials.
Fletch
It's a Flex 4 thing I haven't completely assimilated. But, it relates directly to the skin controlling layout. In theory, in a Spark component you won't ever be modifying the component's state, only the skin state. In a Halo style component, you won't ever use the skin state [as they don't exist].
www.Flextras.com
A: 

Thanks for the answers. Here's what I came up with:

// constructor
public function MyBox() {
    states = new Array();

    for each (var name:String in ['working', 'active', 'disabled']) {
        var state:State = new State();
        state.name = name;
        states.push(state);
    }
}
Fletch