tags:

views:

221

answers:

3

I've just found out about View States in Flex (v3.0), but I am not really sure how widely this is used in real-world applications. Is it a good practice to use it? Are there any pitfalls such as maintainability for instance?

+1  A: 

I started using states in my app (enterprise-level application) in various places, and have since refactored them all out. Most of my MXML has been replaced by pure AS3 components, and I'm skeptical of binding and the flex component lifecycle. There's a lot of convenience tricks advertised in the Flex framework that begin to feel cumbersome and slow once you really start using them.

Like anything, your own mileage will vary. They might be useful if you can avoid the "everything is a nail" syndrome. Maybe I couldn't.

Glenn
Thanks Glenn. Yes, as I am learning Flex, I realised that Adobe offers many 'easy tricks' that if used in a more complex project would probablly cause trouble later on. It would be really helpful to be able to see the source and structure of a real-world application because at this stage it is very difficult to understand what is useful and what is not.
Flex source is mostly open. Take a walk through their components and see what they do to create them. That's as real-world as you'll get. You'll just be doing variations on those. And notice that they rarely, if ever, use MXML to write their own components. I don't recall ever seeing states used either. That being said, I wouldn't go and emulate their coding practices either. Like any real-world application, there's lots of hacks and cruft.
Glenn
+2  A: 

I also used states in an enterprise-level app. But very lightly.

States can be really useful to clean up your code for some cases. There is a performance down side, if a state adds a child, the child will not be removed from the list until you go back to that state and and add a new child.

I think states can be useful if you need to enable/disable make visible/invisible a bunch of components back and forth (depending on a state). This is the ideal use-case of states in Flex.

Ammar
Thanks Ammar, very useful info.
+1  A: 

I've used states heavily and find them a far more elegant solution that lots of conditional code. Indeed, I initially avoided them for some of the reasons given above, but after the app became very complex, with multiple variant "states" I realized that I was fighting the framework.

Frankly, I'd make the same observation about bindings. If you don't understand some of the subtleties, they can be your undoing, it's true. However, writing your own code to achieve the same thing seems like duplication of effort. Take a look at the generated code sometime and also read some of the good deep-dives on bindings out there.

verveguy