I really wanted to title this post: One <Transition> To Rule Them All. But that wouldn’t be very descriptive. Actually, it would be but only after you had read the post.
Here was the situation I was in:
- I had lots of components that basically comprised a view stack without being in a view stack
- I wanted to do a <Fade> transition between each one when a new component came into view
- I have a state for each component instance
This is very easy to set up. Each component has the properties:
visible.myState="true" visible="false"
So when we’re in myState this particular component will be the only one visible. No problem. Except that I have to have a <Transition toState=”…> to go to each and every state. At least they are all the same but then if I want to change any of the transition details I have to do it to each one. That’s like the definition of sloppy coding. Even if it takes less than a minute to update the entire batch it just goes against the very nature of organized code.
Fortunately you can use a wildcard in the toState parameter:
<Transition toState="*">
Below is a simple example. There are four images stacked on top of each other and a state associated with each. The transition reads like this:
<s:transitions>
<s:Transition toState="*" autoReverse="true">
<s:Fade targets="{ [ wolverine, batman,
ryanStewart, invisibleMan ] }" />
</s:Transition>
</s:transitions>
An interesting note: I never did run across any documentation on this. I was just stuck in the middle of updating all my transitions -again- and I thought to myself, “Sure would be nice if I could use a wildcard here.” So I just guessed that it might work and tried it. Sure enough it did. 10-out-of-10 to the Flex SDK team for adding this little nugget. Minus several million for not documenting it very well. :)
| view source |
And by the way: Did anyone ever expect to see Ryan Stewart’s name in a group with Wolverine, Batman and The Invisible Man? :)





Pssst… Take a look at this – http://help.adobe.com/en_US/Flex/4.0/UsingSDK/W…
New comment box I see :)
-KillerSpaz
I figured it was documented. Just not entirely obvious. :) I had no idea it was the default. That's funny.
It doesn't help that my ASDocs don't work in Flash Builder 4. :(
Yeah, I switched from my home-grown comment box to DISQUS. So far I like it pretty well.
Was already working with Flex 3, it's not Flex 4-new-states-syntax related ;)
Fabien
http://www.flex-tutorial.fr
What? Flex 3 had states?!?!? :)
Really, I NEVER used states in Flex 3. I just wrote all my own transitions and did everything manually. What a time saver Flex 4 states have become.
I think we even get points for documenting it… http://help.adobe.com/en_US/FlashPlatform/beta/… ;)
Okay, I'm starting to feel like an ass for not realizing that wildcards could be used. But I did read a lot about Flex 4 states and never noticed the documentation and never saw an example of it being used. It just makes me wonder how many more gems I've missed that are hiding in plane sight.
BTW, awesome blog you have. I saw your PixelBender transition example in a video but didn't know who did it originally. Glad to have found it.
nice…great flex 4. work start on it.
Hi, Thanks for this. I am a complete beginner with Flex and have found it really difficult to find useful examples of straightforward (one would think) stuff. I don't understand the line xmlns:utils="com.polyGeek.utils.*" Presumably this is something on your server without which this does not work? Or am I being thick?
@Simon The xmlns=… is a namespace. Think of it as the same thing as an import statement in Actionscript. Suppose I have a file in my com.polyGeek.utils folder named BatBelt.as. Instead of typing: com.polyGeek.utils.BatBelt every time I want to access the BatBelt class I can just type: utils.BatBelt.
Hope that helps.