concept view state in category flex

appears as: view states, view state
Hello! Flex 4

This is an excerpt from Manning's book Hello! Flex 4.

In this chapter, you’ll start learning Spark, which is the new set of components, containers, and graphics primitives in Flex 4. This will be a “how-to” chapter: we’ll save diving into the Spark component model until the next chapter (which discusses view states, containers, CSS styling, and skinning). This chapter provides enough examples of using Spark that when it comes time to tackle the theory you’ll have plenty of examples in your head.

The toggleState function switches states to either the default state (which happens to be named default) or to the newState based on the value of the currentState. If the currentState is equal to the newState, the user has already switched to stateOne, stateTwo, or stateThree, so we want to switch back to the default state. Otherwise, we want to switch to the newState (which is stateOne, stateTwo, or stateThree).
The first state is the default state. Naming it default is a convention you will sometimes encounter, but it’s not a requirement.
States can also belong to one or more stateGroups. We’re using them to define stateOne as a state in which the stateTwoPanel and stateThreePanel aren’t shown. This way, we can use excludeFrom. (This is a bit contrived, since I could’ve also just used includeIn, but I wanted to show both excludeFrom and includeIn, as well as stateGroups.)
The stateOnePanel is at the top left, with the title “State One Panel” and the Kanji of Matsuo Basho’s name (Matsuo being the family name). The stateOne view state is the state in which the stateOnePanel is expanded to take up the full app size, minus a 10-pixel border. We do this by defining the default height as 100 but the bottom.stateOne as 10, meaning that in stateOne the component is stretched so that its bottom is only 10 pixels from the bottom of the app. (I’ve had mixed success using percentHeight and percentWidth in conjunction with normal height and width using view states; this is a more effective way of doing this.) Finally, when learning how to use percentage sizing like percentWidth and percentHeight; constraint-based-layout like top, bottom, left, and right; and absolute positioning, there’s no better way to learn than making a toy app with a few Panels in it and experimenting with the layouts. Please think of this app as a good basis for your own experiments.
Yes, you can actually paste Kanji into Flex 4 source code!
The stateTwoPanel is the bottom left (when in the default state) or the full app size (in the stateTwo state).
The stateThreePanel is on the right (when in the default state) or the full app size (in the stateThree state).
The 
 entity is used to insert newlines.

View states, which are vastly improved in Flex 4, are an easy way of making your app dynamic. They also show the importance of properly componentized design—although in this app we define the HPanel content all in one file, in real applications you want to build encapsulated components so that the application state logic and the component logic is separate. Also, note that view states aren’t just limited to the application—components can have their own view states that you can switch between.

In the next workshop session we’ll explore the basics of effects. Besides what we’ll see in the next session, effects can be used to transition between view states in a more exciting way.