O'Reilly logo

Flex 3 Cookbook by Joshua Noble, Todd Anderson

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

States are a powerful tool that encapsulate a lot of the work of creating stateful components, that is, components that have multiple views. These could be controls that need to operate as both an editor and a display, a dialog box with multiple screens, or a component with a menu view and detail view. These multiple views, when contained within a single component, are referred to as states. The Flex Framework defines a class called State, contained within the mx.state package, that lets you define the properties of a particular view within a single component. All UIComponents let you add one or more mx.state.State objects to their states array, which enables you to easily add and remove any child components, control styles, and use Effects and Transitionswhen a State is entered or exited. Frequently, unless there’s a real need to create a separate mechanism to store distinct states and what changes those states entail, using x.states.State is a far cleaner and simpler way to implement multiple states or views within a single component.

States can add children to a component that will be removed by the component as soon as the state is exited. You also can define transitions that will play as the currentState of a component is changed and apply effects to selected children any time the state property is changed. Any properties of a component that are meant to be temporary or that are relevant only to a certain state of a component can be easily and efficiently ...

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