Adobe Flex 3 Help

Switching states at run time

When your Flex application is running, users need ways of switching from one view state to another. You can use Flex Builder to define event handlers for user controls so that users can switch states at run time.

The simplest method is to assign the currentState property to the click event of a control such as a button or a link. The currentState property takes the name of the view state you want to display when the click event occurs. In the code, you specify the currentState property as follows:

click="currentState='viewstatename'"

If the view state is defined for a specific component, you must also specify the component name, as follows:

click="currentState='componentID.viewstatename'"

For more information, see Applying view states in the Adobe Flex 3 Developer Guide.

  1. Ensure that the initial state has a clickable control, such as a Button control.

    In the MXML editor's Design mode, select the control and enter the following value in the On Click field in the Flex Properties view:

    currentState='viewstatename'

    Current state value

  2. If you want to switch to the base state, enter currentState='' (single-quote empty string) instead.

    An empty string specifies the base state.

  3. To test that the states switch correctly in the application when the button is clicked, click the Run button in the MXML editor toolbar.

You can define a transition so that the change between view states is smoother visually. For more information, see Creating a transition.