views:

1911

answers:

3

I have an app that I am currently using a viewstack to display each page and I am wondering is this the right way to go, or should I use different states (or something else).

The site is powered by a menu bar with the top level items of Home, Tools, Support. Underneath the Tools menu is a submenu with Tool1, Tool2, Tool3. Currently when the user clicks on any of the tools in the Tool submenu I bring up a child container from the viewstack (each child is actually in a separete component).

Is this the right way to go, or should I be using states to bring up the appropriate elements for each tool page?

A: 

States are the way to go. You can easily reuse states and expand on their functionality by extending a base state.

Rick J
+2  A: 

It depends on how different the views are. If they are very similar, states are good because they help to effectively reuse a lot of markup already defined in the base component. If they are very different views, the states will be harder to for other developers to maintain because it's not as straightforward as separate components for each view.

Also ViewStack allows for deferred instantiation to be used. This is controlled by the "creationPolicy" attribute. DI means your app will load faster because only the first child of the ViewStack will be instantiated intially. As you navigate to the other children, they will instantiated on demand.

cliff.meyers
Thanks for your information brd6644
R.Vijayakumar
He stated that each child of the view stack is a component, which means only a remove child followed by add child if using states. No nightmare here.ViewStack has no advantage over using states other than the easiness in implementing and mantaining. Deferred instantiation is a bonus. When using states, the components added by a state are also instantiated when that state becomes the current state.
bug-a-lot
A: 

As brd6644 said, if the changes from screen to screen are drastic, use view stacks. It will be a maintenance nightmare to have complex state transformations.

I usually go for a combined viewstack/state solution. Different screen are nicely defined in their own view stack and I use states to switch between them.

Chetan Sastry
thank for your information Chetan Sastry . i have two menu like One is Main menu another one is submenu . If i set Main menu view stacks otpion then how can i set for submenu .
R.Vijayakumar
Use setProperty to set the selectedIndex property of view stack.
Chetan Sastry
if i try like this show some error <mx:SetProperty target="{storeViews.selectedIndex}" value="0" />
R.Vijayakumar
<mx:SetProperty target="{storeViews}" name="selectedIndex" value="0" />
Chetan Sastry