apache-flexflex4viewstatesviewstack

What is the best view architecture in flex?


I have started learning flex 4 and I got myself thinking about how to change views. So I have a question what do people usually use - states or views (ViewStack). The type of web application I am making, can use both, but what do developers use in big projects or maybe they use non of the mentioned before?

Also I have a question about ViewStack. If I write:

<mx:ViewStack id="views" resizeToContent="true" verticalCenter="0" horizontalCenter="0" >
    <s:NavigatorContent id="navOne">
        <s:Label text="asdas" x="0" y="0"/>
    </s:NavigatorContent>

then I can't change location of its child. Label remains in the center of the screen. If I remove vertical and horizontal center from ViewStack and put them in Label's tags, then label will be in top left corner but not in center. How do I control those locations?


Solution

  • As far as you're using Flex 4 you can prefer states. And there are at least two reasons for that:

    1. Flex 4 states are much more declarative than in Flex 3.
    2. Flex 4 hasn't Spark implementation of ViewStack and it is rather obsolete (necessarity of using NavigatorContent with Spark container is another proof of that fact).

    The second part of the question. The problem is your ViewStack hasn't any size. So finally it has size of content (Label size). So verticalCenter and horizontalCenter are just alignment of your ViewStack. To control size and alignment of ViewStack you should care about sizes. Something like:

    <mx:ViewStack id="views" resizeToContent="true" verticalCenter="0" 
        horizontalCenter="0" width="500" height="300" >
        <s:NavigatorContent id="navOne" width="100%" height="100%">
            <s:Label text="asdas" x="0" y="0"/>
        </s:NavigatorContent>