Mobile Flex: ViewNavigator Basics
Flex 4.5 provides some pretty slick updates and enhancements, the least of are the of Mobile components and the ability to easily slam out some pretty nice mobile apps. The first thing I’d like to talk about is a new concept, the ViewNavigator. The ViewNavigator provides some pretty intense functionality such as view management.
What is the ViewNavigator?
The ViewNavigator keeps track of your views. It does this by keeping your views in a list. To add a new view you ‘push’ the view into the list, to remove a view you can ‘pop’ a view out of the list. You can think of it as a stack – first in, last out – and the last view in is the visible view.
Using the ViewNavigator
Using the view navigator is a pretty straight forward process of capturing a user interaction, such as a button click, then pushing the new View into the ViewNavigator’s stack.
For example, let’s pretend that you have a new Flex mobile project. The default view of that project has a button, that when clicked should display another view named MyNewView. MyNewView also has a button, that when clicked returns you to the home view.
Home View Component
In the Home View component all you really need to worry about the click handler on the button:
label="NEXT" width="100%" click="navigator.pushView(MyNewView)" />
The click handler calls the pushView() method on ‘navigator‘, a property available from the View class, passing it the class name of the View that you want to display. We’ll cover getting data into that view and transitions in other posts. The creation of the new View & default transition are all handled by the framework.
MyNewView Component
The MyNewView View component is basically the same thing:
label="BACK" width="100%" click="navigator.popView()" />
You call popView() on the ‘navigator‘ property which removes the view from the stack displaying the Home view again.
Here is a quick screen cast of an application using similar code:








Hi, i want to implement view navigator logic on a popup. I have a button called settings and clicking on that I’m creating a popup with different items in it. Clicking on each item inside the popup the present view should be pushed and clicked view should come up.
Im using this is in Qnx container.Can any one please help me how can we implement push and pop with out using view navigator application
Thanks.
The ViewNavigator has the push and pop view management baked in. If you don’t want to use the ViewNavigator, you’ll need to build your own system to manage the views using a push and pop view-stack API.
Hi,
thx for tutorial.
there is typo in your code should be “navigator” instead of “navigtor”
Thanks – we’ve updated the code in the post.