TDOT Blog Touchwood Creative

Register | Forgot password?

Author Info

Name
Ben Bishop

Job Title
Senior Interactive Developer



Touchwood is continuing to grow!

We are looking for talented Flex developers to join our Interactive Group. If you have any interest we would love to meet you. Please email your resume to us at:

jobs@touchwoodcreative.com


A "Link" Approach to Managing Screens in Flex

Problem:

You want to "link" mutliple MXML files to each other via buttons.

Note: For new Flex developers, it is sometimes easier to think of "linking" MXML files together. Also note, because of Flashplayer's garbage collection issues this may not be the most ideal solution for very big applications and a ViewStack may indeed work better.

Solution:

Create a ScreenManager singleton class that clears and creates fresh new instances of MXML components for the application.

Note: You can also use a ViewStack to manage mutliple screens and have navigation devices such as buttons just change the selected index of the ViewStack. However, for this scenaro, let's say we want fresh new screens. (ViewStacks maintain its children's states. So, for example,if you have a form and navigate away from it, if you were to return all of the values would still be there.)

Implementation:

First download the example project via this post or checkout the library project via svn from here: http://tdotcommunity.googlecode.com/svn/trunk/ tdotcommunity-read-only.

Once you've plugged your project into the library all you have to do is something like this to get a button to load a new screen (screen2 is the name of the MXML file you wish to go to):

<mx:Button label="Go to Screen 2" click="{ ScreenManager.getInstance().setScreen(screen2)}"/>

Viola! That's it!

 

Attached to this post is the library project file and an example project.

AttachmentSize
ScreenMgmtExample.zip517.98 KB
© Touchwood Creative 2007 | We use Firefox