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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Example 6-11. Component.as<br />

package<br />

{<br />

}<br />

import flash.errors.IllegalOperationError;<br />

import flash.display.Sprite;<br />

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

public class Component extends Sprite<br />

{<br />

}<br />

protected var parentNode:Composite = null;<br />

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

{<br />

throw new IllegalOperationError(<br />

"add operation not supported");<br />

}<br />

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

{<br />

throw new IllegalOperationError(<br />

"remove operation not supported");<br />

}<br />

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

{<br />

throw new IllegalOperationError(<br />

"getChild operation not supported");<br />

return null;<br />

}<br />

// ABSTRACT Method (must be overridden in a subclass)<br />

public function update( ):void {}<br />

internal function setParent(aParent:Composite):void<br />

{<br />

parentNode = aParent;<br />

}<br />

public function getParent( ):Composite<br />

{<br />

return parentNode;<br />

}<br />

The Composite class shown in Example 6-12 extends the Component class and overrides<br />

the update( ) method.<br />

224 | Chapter 6: Composite Pattern

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

Saved successfully!

Ooh no, something went wrong!