Extended Example: Dynamic Command Object Assignment | 277
objects to the podcast radio station buttons based on the state of the application, or,
in this case, the selected podcast genre.
The DynamicControlButtons class, shown in Example 7-31, extends the
ControlButtonsclass from Example 7-29. It keeps track of the selected genre in the
propertycurrentGenre(line 7). The two podcast genres are defined by the static con-
stantsNEWSandMUSIC(lines 5-6). It also declares and initializes two arrays (lines 9-10)
to hold the command objects assigned to the news and music genres for the three
station buttons.
ThesetGenre( )method sets the genre by setting thecurrentGenreproperty (lines 18-
27). ThesetGenreCommand( )method (lines 29-38) assigns the passed commands to
the two arrays that hold the news and music command objects. After any changes to
the state of the application, theupdateCommandButtons( )method is called to dynami-
cally assign the command objects for the chosen genre to the station buttons (posi-
tions 1-3 on thecommandList array).
Figure 7-6. Podcast radio with music and news genre buttons
Example 7-31. DynamicControlButtons.as
1 package
2 {
3 class DynamicControlButtons extends ControlButtons
4 {
5 public static const NEWS:uint = 0;
6 public static const MUSIC:uint = 1;
7 var currentGenre:uint = NEWS;
8
9 var newsPodcastCommands:Array;
10 var musicPodcastCommands:Array;
11
12 public function DynamicControlButtons( )
13 {
14 this.newsPodcastCommands = new Array(3);