274 | Chapter 7: Command Pattern
Push Button Invokers for the Radio
TheControlButtonsclass shown in Example 7-29 is identical to theInvokerPanel
class (Example 7-15) discussed previously. The only difference is that now the
TextButtonclass has to be imported from theutilspackage. Its main function is to
hold push button instances and command objects associated with them, and exe-
cute the corresponding command when a button’s clicked.
44 var url = xml..item[0].enclosure.attribute("url");
45 // load audio and play
46 var request:URLRequest = new URLRequest(url);
47 var audio:Sound = new Sound( );
48 audio.addEventListener(IOErrorEvent.IO_ERROR, loadError);
49 audio.load(request);
50 audioChannel.stop( ); // stop previous audio
51 audioChannel = audio.play( );
52 }
53
54 private function loadError(event:Event):void
55 {
56 trace("Load error " + event);
57 }
58 }
59 }
Example 7-29. ControlButtons.as
package
{
import flash.display.;
import flash.events.;
import utils.*;
class ControlButtons extends Sprite
{
var commandList:Array;
var buttonList:Array;
public function ControlButtons( )
{
this.commandList = new Array(5);
this.buttonList = new Array(5);
}
public function setCommand(nSlot:int, c:ICommand):void
{
this.commandList[nSlot] = c;
}
public function setButton(nSlot:int, sName:String):void
{
Example 7-28. Radio.as