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-19. NewModel.as (continued)<br />

}<br />

}<br />

override public function getMapURL( ):String {<br />

switch(chosenMapType) {<br />

case 1:<br />

return this.aIRImageURLs[chosenRegion];<br />

break;<br />

default:<br />

return this.aImageURLs[chosenRegion];<br />

break;<br />

}<br />

}<br />

The getMapURL( ) method was overridden, as the returned image URL now depends on<br />

the currently chosen map type. Note that we didn’t modify any existing code, but<br />

extended the existing model class Model to implement the new interface requirements.<br />

Adding a New Controller<br />

A new controller (Example 12-20) is necessary to handle the input to the map type<br />

selector view. We can implement the same ICompInputHandler interface<br />

(Example 12-14) for the new controller.<br />

Example 12-20. MapTypeController.as<br />

package<br />

{<br />

public class MapTypeController implements ICompInputHandler {<br />

}<br />

}<br />

private var model:Object;<br />

public function MapTypeController(oModel:INewModel)<br />

{<br />

this.model = oModel;<br />

}<br />

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

{<br />

(model as INewModel).setMapType(index); // update model<br />

}<br />

Adding a New View<br />

We will add a new view (Example 12-21) that consists of two grouped radio buttons<br />

that allow the user to select from either visible or infrared map images. The view will<br />

use the built-in RadioButtton <strong>com</strong>ponent in Flash CS3. Make sure the radio button<br />

<strong>com</strong>ponent is dragged from the Components panel into the Library panel in the<br />

Flash document.<br />

454 | Chapter 12: Model-View-Controller Pattern

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

Saved successfully!

Ooh no, something went wrong!