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 ...

Get Professional Adobe® Flex® 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.