| Using Flex Builder 2 > Developing a Flex Application User Interface > Adding View States and Transitions > 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 Flex 2 Developer's Guide.
Select the control in the MXML editor's Design mode, and enter the following value in the On Click text box in the Flex Properties view:
currentState='viewstatename'
An empty string specifies the base state.
You can define a transition so that the change between view states is smoother visually. For more information, see Creating a transition.
Flex 2.01