O'Reilly logo

Professional Adobe® Flex® 3 by Joe Berkovitz, David Hassoun, Andrew Trice, Tom Sugden, Todd Prekaski, Jun Heider, Peter Ent, Joseph Balderson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 20. State Management

A Flex application can do a lot of things. Managing all of the user interface components can quickly become complex. Sometimes you need components that do nearly the same thing, but are different enough to make you create several components. But what if one component could have two looks? That is exactly what States in Flex do. With States you can condense your application yet still make your project easy to maintain.

This chapter covers States: what they are, how you use them, and how to manipulate them in ActionScript.

What Are States?

Have you ever written a component where a user's action changes the appearance of the component? For example, perhaps you have wanted the ability to expand a component, opening a space to show more details. Or maybe you have wanted to enable some fields and disable others.

Those are the times when using a State can make writing code easier. A State provides changes to a component's own properties and styles, and changes to a component's children's properties and styles, as well as temporarily adding and removing children from the component.

The collection of things to be changed is known as an override. Suppose that you have a component called EmployeeDetails. The component initially has the employee name and button labeled "Details." When the Details button is clicked, the component expands to show the employee's ID number, department, manager, and so forth.

You could write the component using ActionScript code to add in ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required