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.

implementations in the MVC. Our view elements are going to get more <strong>com</strong>plexas<br />

they can implement a third pattern, the <strong>com</strong>posite (see Chapter 6 for examples of the<br />

<strong>com</strong>posite pattern). Implementing views as elements of a <strong>com</strong>posite pattern only<br />

makes sense for <strong>com</strong>plexnested user interfaces that contain multiple views. Nested<br />

views bring several advantages to updating the user interface, as updates can cascade<br />

down the <strong>com</strong>posite view tree structure. Also, <strong>com</strong>posite views can create and<br />

remove child views based on application state and user mode. A good example of a<br />

<strong>com</strong>plexuser interface is the Properties inspector panel in the Flash authoring environment.<br />

The Properties inspector is context sensitive, and adds or removes user<br />

interface elements based on the object selected on the stage.<br />

Component and <strong>com</strong>posite views<br />

The first step is to create the <strong>com</strong>ponent and <strong>com</strong>posite classes for the view. These<br />

classes should behave as abstract classes and should be subclassed and not instantiated,<br />

as shown in Example 12-7.<br />

Example 12-7. ComponentView.as<br />

package<br />

{<br />

import flash.errors.IllegalOperationError;<br />

import flash.events.Event;<br />

import flash.display.Sprite;<br />

// ABSTRACT Class (should be subclassed and not instantiated)<br />

public class ComponentView extends Sprite {<br />

{<br />

protected var model:Object;<br />

protected var controller:Object;<br />

public function ComponentView(aModel:Object, aController:Object = null)<br />

{<br />

}<br />

this.model = aModel;<br />

this.controller = aController;<br />

public function add(c:ComponentView):void<br />

{<br />

throw new IllegalOperationError("add operation not supported");<br />

}<br />

public function remove(c:ComponentView):void<br />

{<br />

throw new IllegalOperationError("remove operation not supported");<br />

}<br />

public function getChild(n:int):ComponentView<br />

{<br />

throw new IllegalOperationError("getChild operation not supported");<br />

Minimalist Example of an MVC Pattern | 437

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

Saved successfully!

Ooh no, something went wrong!