ActionScript 3.0 Design Patterns

(Chris Devlin) #1
Extended Example: Dynamic Command Object Assignment | 279

Note that the receiver for both these commands is of typeDynamicControlButtons,


which is the invoker. Here the invoker is also the receiver for the commands that set


the podcast genre.


Dynamic Command Assignment Setup from the Client


The client has to specify command objects for both the music and news genres to the


station buttons (the first three buttons), and the commands to change the genre (to


the last two buttons). The dynamic assignment of command objects to the station


buttons takes place in the invoker. The client essentially programs the buttons on the


class SetToMusicGenreCommand implements ICommand
{
var receiver:DynamicControlButtons;


public function SetToMusicGenreCommand(
rec:ControlButtons):void
{
this.receiver = rec;
}


public function execute( ):void
{
this.receiver.setGenre(
DynamicControlButtons.MUSIC);
}
}
}


Example 7-33. SetToNewsGenreCommand.as


package
{
class SetToNewsGenreCommand implements ICommand
{
var receiver:DynamicControlButtons;


public function SetToNewsGenreCommand(
rec:ControlButtons):void
{
this.receiver = rec;
}


public function execute( ):void
{
this.receiver.setGenre(DynamicControlButtons.NEWS);
}
}
}


Example 7-32. SetToMusicGenreCommand.as (continued)

Free download pdf