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 6-7. Main.as (client code to remove nodes) (continued)<br />

}<br />

}<br />

trace("display tree");<br />

trace("============");<br />

root.operation( );<br />

trace("remove first child of the second child of root");<br />

trace("==============================================");<br />

root.getChild(2).remove(root.getChild(2).getChild(1));<br />

root.operation( );<br />

trace("remove the second child of root");<br />

trace("===============================");<br />

root.remove(root.getChild(2));<br />

root.operation( ); }<br />

Executing the statements in Example 6-7 will generate the following output. The<br />

operation( ) method traverses the tree structure recursively using a depth-first<br />

approach, and prints the <strong>com</strong>ponent names accordingly.<br />

display tree<br />

============<br />

root<br />

<strong>com</strong>posite 1<br />

leaf 1<br />

leaf 2<br />

<strong>com</strong>posite 2<br />

leaf 3<br />

leaf 4<br />

leaf 5<br />

leaf 6<br />

remove first child of the second child of root<br />

==============================================<br />

root<br />

<strong>com</strong>posite 1<br />

leaf 1<br />

leaf 2<br />

<strong>com</strong>posite 2<br />

leaf 4<br />

leaf 5<br />

leaf 6<br />

remove the second child of root<br />

===============================<br />

root<br />

<strong>com</strong>posite 1<br />

leaf 1<br />

leaf 2<br />

leaf 6<br />

You can easily visualize what happens to the <strong>com</strong>ponent tree by looking at what<br />

happens graphically in Figure 6-5.<br />

216 | Chapter 6: Composite Pattern

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

Saved successfully!

Ooh no, something went wrong!