O'Reilly logo

ActionScript 3.0 Design Patterns by Chandima Cumaranatunge, William Sanders

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Selecting and Playing Sound and Video

Considering how Flash handles sound and video, they both share some actions in common. For example, both need to have filenames to play, and both have to somehow have a "play" command. Using the Template Method, we should be able to key in on those two functions of getting a filename and playing, and placing them into an algorithm. However, because of the differences between the two media, we'll leave the details up to the concrete classes. The locked operation that'll be in the main abstract class will be a text header.

Setting Up the Format

The initial abstract class containing an algorithm for a filename selector and play-command operation is pretty simple, because the operations have no content. A third operation that adds a text message to the top of the screen will be locked, and while it's relatively simple, it requires importing a number of packages. Open a new ActionScript file, copy the contents of Example 9-8, and save it using the caption name for the filename.

Example 9-8. VidAudio.as

package { import flash.display.Sprite; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.text.TextFormat; //Abstract Class class VidAudio extends Sprite { private var mText:TextField; //Template method public final function mediaProducer ():void { selectMedia (); playNow (); fromMediaDesign (); } protected function selectMedia ():void { //Awaiting instructions } protected function playNow ():void { //Awaiting instructions } ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required