ActionScript 3.0 Design Patterns

(Chris Devlin) #1
Example: Weather Maps | 447

The Views


The weather map application consists of two views. The first is a user interface ele-


ment that contains a combo bo xto select a region to display. The second view dis-


plays the corresponding regional satellite image.


We will use the built-inComboBoxandUILoadercomponents in Flash CS3 to imple-


ment the user interface elements in each view. Components are movie clips with


parameters that allow you to modify their appearance and behavior. They allow


developers to build Flash applications with consistent behavior and appearance with-


out creating custom user interface elements such as buttons and sliders. For the


weather map application, we need to drag theComboBoxandUILoadercomponents


from theComponents panelto theLibrary panelin our Flash document. The Compo-


nents and Library panels can be accessed from the Windows menu in Flash CS3.


Note that we don’t want to place the component on the stage. We’ll add the compo-


nents to the stage at runtime using ActionScript. TheComboBoxcomponent uses sev-


eral additional assets as well. Your library panel will look like Figure 12-4 after the


ComboBox andUILoader components are dragged into it.


We can now develop the combo bo xand map views for the application. The combo


box view will be a composite view containing the map view as one of its children.


Example 12-15. Controller.as (Controller for the weather map example)


package
{
public class Controller implements ICompInputHandler
{


private var model:Object;


public function Controller(aModel:IModel)
{
this.model = aModel;
}


public function compChangeHandler(index:uint):void {
(model as IModel).setRegion(index); // update model
}
}
}

Free download pdf