ActionScript 3.0 Design Patterns

(Chris Devlin) #1
Selecting and Playing Sound and Video | 349

In setting up the video play, not only did we create a play trigger, we also added


functions for cleaning up after the play was complete, and a way to extract duration


metadata from the video file being played. That makes the class much handier for


use in other applications. In both the video and audio classes, the extension names


were added so that all the user needs is a media name without an extension.


Playing the Media


Finally, the application needs a user interface to choose between playing sounds or


video. It needs functions to call one of two of the concrete template method classes


and some functions to put the interface buttons where they’re needed. Open a new


ActionScript file and enter Example 9-13 code, saving the file using the caption name.


Be sure to save it in the same folder as the other files that make up the application.


Example 9-13. PlayMedia .as


package
{
import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.events.MouseEvent;


public class PlayMedia extends Sprite
{
var videoButton:VideoButton;
var tuneButton:TuneButton;


public function PlayMedia ( ):void
{
doButton ( );
}
//Get the buttons out of the library and put them on display
private function doButton ( ):void
{
tuneButton=new TuneButton( );
videoButton=new VideoButton( );
addChild (tuneButton);
addChild (videoButton);
tuneButton.x=((stage.stageWidth/2)-
(1.5*tuneButton.width)), tuneButton.y=30;
videoButton.x=((stage.stageWidth/2)+5), videoButton.y=30;
tuneButton.addEventListener
(MouseEvent.CLICK,getTune,false,0,true);
videoButton.addEventListener
(MouseEvent.CLICK,getVideo,false,0,true);
}


//Invoke the template method (mediaProducer) for the video
private function getVideo (e:MouseEvent):void
{
var vidUp:VidAudio=new Vid( );

Free download pdf