10.12.2012 Views

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Example 9-13. PlayMedia .as (continued)<br />

}<br />

}<br />

vidUp.mediaProducer ( );<br />

addChild (vidUp);<br />

}<br />

//Invoke the template method (mediaProducer) for the audio<br />

private function getTune (e:MouseEvent):void<br />

{<br />

var tuneUp:VidAudio=new Audio( );<br />

tuneUp.mediaProducer ( );<br />

addChild (tuneUp);<br />

}<br />

Most of the work in this application has been done with <strong>ActionScript</strong>, but a Flash document<br />

file will be used to create the buttons for the UI. The following steps show how:<br />

1. Open a new Flash document and save it as PlayMedia.fla in the same folder as<br />

the other files in the application.<br />

2. Select Insert ➝ New Symbol from the menu bar.<br />

3. In the New Symbol dialog box, select Button as the type. Type VideoButton in<br />

the Name window, and click the Export for <strong>ActionScript</strong> checkbox. Click OK to<br />

enter the Symbol editing mode.<br />

4. Select the Rectangle tool, and set the Rectangle Corner Radius to 8. Draw a rectangle<br />

with the dimensions W=49 and H=60.<br />

5. Add a second layer while still in the Symbol editing mode. Name the top layer<br />

“Text” and the bottom layer “Shape.” In the Text layer, add the static text label,<br />

“Video.” Click OK.<br />

6. Repeat Steps 2 to 5, substituting TuneButton for the button name, and “Tune” for<br />

the static text label in Step 5.<br />

7. Your Library panel should show two buttons, one named VideoButton and the<br />

other named TuneButton. Each is considered a class, and instances of each are<br />

used in the PlayMedia class.<br />

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

FLV file. Rename the MP3 file to iBlues.mp3 and the FLV file to media.flv.<br />

Figure 9-5 shows the application running the video.<br />

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

can be extensive. Looking at the two main concrete classes, the methods handling the<br />

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

mechanism for starting the play, it also has a routine for extracting the metadata from<br />

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

sound does not use the display array to add sound children. That’s because the sound<br />

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

350 | Chapter 9: Template Method Pattern

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!