ActionScript 3.0 Design Patterns

(Chris Devlin) #1

350 | Chapter 9: Template Method Pattern


Most of the work in this application has been done with ActionScript, but a Flash doc-


ument file will be used to create the buttons for the UI. The following steps show how:



  1. Open a new Flash document and save it asPlayMedia.flain the same folder as
    the other files in the application.

  2. Select Insert➝ New Symbol from the menu bar.

  3. In the New Symbol dialog box, select Button as the type. TypeVideoButtonin
    the Name window, and click the Export for ActionScript checkbox. Click OK to
    enter the Symbol editing mode.

  4. Select the Rectangle tool, and set the Rectangle Corner Radius to 8. Draw a rect-
    angle with the dimensions W=49 and H=60.

  5. Add a second layer while still in the Symbol editing mode. Name the top layer
    “Text” and the bottom layer “Shape.” In the Text layer, add the static text label,
    “Video.” Click OK.

  6. Repeat Steps 2 to 5, substitutingTuneButtonfor the button name, and “Tune” for
    the static text label in Step 5.

  7. Your Library panel should show two buttons, one namedVideoButtonand the
    other namedTuneButton. Each is considered a class, and instances of each are
    used in thePlayMedia class.


To work with this application, you’ll need two additional files; an MP3 file and an


FLV file. Rename the MP3 file to iBlues.mp3 and the FLV file to media.flv.


Figure 9-5 shows the application running the video.


As you can see by this example, the “details” changed in the algorithm’s operations


can be extensive. Looking at the two main concrete classes, the methods handling the


video are far more extensive than those handling the audio. Not only does it include a


mechanism for starting the play, it also has a routine for extracting the metadata from


the FLV file, and displaying it on the stage in a text field. In contrast the path taken for


sound does not use the display array to add sound children. That’s because the sound


isn’t displayed on the stage, and so no display elements are required.


vidUp.mediaProducer ( );
addChild (vidUp);
}
//Invoke the template method (mediaProducer) for the audio
private function getTune (e:MouseEvent):void
{
var tuneUp:VidAudio=new Audio( );
tuneUp.mediaProducer ( );
addChild (tuneUp);
}
}
}


Example 9-13. PlayMedia .as (continued)

Free download pdf