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 7-32. SetToMusicGenreCommand.as (continued)<br />

}<br />

class SetToMusicGenreCommand implements ICommand<br />

{<br />

var receiver:DynamicControlButtons;<br />

}<br />

public function SetToMusicGenreCommand(<br />

rec:ControlButtons):void<br />

{<br />

this.receiver = rec;<br />

}<br />

public function execute( ):void<br />

{<br />

this.receiver.setGenre(<br />

DynamicControlButtons.MUSIC);<br />

}<br />

Example 7-33. SetToNewsGenreCommand.as<br />

package<br />

{<br />

class SetToNewsGenreCommand implements ICommand<br />

{<br />

var receiver:DynamicControlButtons;<br />

}<br />

}<br />

public function SetToNewsGenreCommand(<br />

rec:ControlButtons):void<br />

{<br />

this.receiver = rec;<br />

}<br />

public function execute( ):void<br />

{<br />

this.receiver.setGenre(DynamicControlButtons.NEWS);<br />

}<br />

Note that the receiver for both these <strong>com</strong>mands is of type DynamicControlButtons,<br />

which is the invoker. Here the invoker is also the receiver for the <strong>com</strong>mands that set<br />

the podcast genre.<br />

Dynamic Command Assignment Setup from the Client<br />

The client has to specify <strong>com</strong>mand objects for both the music and news genres to the<br />

station buttons (the first three buttons), and the <strong>com</strong>mands to change the genre (to<br />

the last two buttons). The dynamic assignment of <strong>com</strong>mand objects to the station<br />

buttons takes place in the invoker. The client essentially programs the buttons on the<br />

Extended Example: Dynamic Command Object Assignment | 279

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

Saved successfully!

Ooh no, something went wrong!