10.12.2012 Views

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Example 12-15. Controller.as (Controller for the weather map example)<br />

package<br />

{<br />

public class Controller implements ICompInputHandler<br />

{<br />

}<br />

}<br />

The Views<br />

private var model:Object;<br />

public function Controller(aModel:IModel)<br />

{<br />

this.model = aModel;<br />

}<br />

public function <strong>com</strong>pChangeHandler(index:uint):void {<br />

(model as IModel).setRegion(index); // update model<br />

}<br />

The weather map application consists of two views. The first is a user interface element<br />

that contains a <strong>com</strong>bo boxto select a region to display. The second view displays<br />

the corresponding regional satellite image.<br />

We will use the built-in ComboBox and UILoader <strong>com</strong>ponents in Flash CS3 to implement<br />

the user interface elements in each view. Components are movie clips with<br />

parameters that allow you to modify their appearance and behavior. They allow<br />

developers to build Flash applications with consistent behavior and appearance without<br />

creating custom user interface elements such as buttons and sliders. For the<br />

weather map application, we need to drag the ComboBox and UILoader <strong>com</strong>ponents<br />

from the Components panel to the Library panel in our Flash document. The Components<br />

and Library panels can be accessed from the Windows menu in Flash CS3.<br />

Note that we don’t want to place the <strong>com</strong>ponent on the stage. We’ll add the <strong>com</strong>ponents<br />

to the stage at runtime using <strong>ActionScript</strong>. The ComboBox <strong>com</strong>ponent uses several<br />

additional assets as well. Your library panel will look like Figure 12-4 after the<br />

ComboBox and UILoader <strong>com</strong>ponents are dragged into it.<br />

We can now develop the <strong>com</strong>bo boxand map views for the application. The <strong>com</strong>bo<br />

box view will be a <strong>com</strong>posite view containing the map view as one of its children.<br />

Example: Weather Maps | 447

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!