Home > Articles > Web Development > Dreamweaver & Flash

  • Print
  • + Share This
This chapter is from the book

Project: Synchronized Images Template

This project is simply another template that works with all the code you’ve produced so far. Specifically, the CaptionHolder.as class loads the .swf file you’ll create in this project just like it does captionText1.swf and captionText2.swf. However, the purpose of this template isn’t solely for captions. Rather, you’ll specify frame labels that contain images, or any Flash graphic or animation, that you want to appear at synchronized times during the video. This project also incorporates the option of adding parameters to cue points (discussed earlier) to stuff even more information into each cue point.

Steps

  1. Encoding the video
  2. Preparing to gather cue points
  3. Creating an animated sequence
  4. Gathering the cue points
  5. Implementing the ActionScript in imagesTemplate.fla
  6. Entering the ActionScript in main_coffee.fla
  7. Testing main_coffee.fla

Step 1: Encoding the Video

Create a new file in Flash and save it as main_coffee.fla. Select File, Import to Stage and then select the coffee_house_1969.mov public domain excerpt, located in the source_media folder. Step through the video import process, accepting all the defaults to produce coffee_house_1969.flv. You won’t be injecting Event or Navigation cue points during this phase.

Step 2: Preparing to Gather Cue Points

Select Control, Test Movie and then click Play to watch the video a few times, noting when the subject says the following phrases:

  • "Circumscribed clientele"
  • "cool people on campus"
  • "not meaning derogatorily"
  • "swinging" (and then "swinging" again)
  • "coffee house"
  • "place to be and the place to be seen"

Step 3: Creating an Animated Sequence

Create a new file and save it in your working directory as imagesTemplate.fla. Select Modify, Document and set both the width and height to 250. Select Insert, New Symbol. Make sure that the Movie Clip option is selected and name the symbol Content. Click OK and you’ll be inside this clip. To see the edges of the stage, draw a rectangle that’s 250 x 250 pixels. Position the rectangle inside the Content symbol so the upper-left corner of the rectangle aligns with the center of the Content symbol. Select Modify, Timeline, Layer Properties and then name the layer Content, click the Lock option, and change the layer type option to Guide (see Figure 3.21). Because we want the outline to guide us over several frames, click the cell in frame 25 and press F5 to insert frames.

Figure 3.21

Figure 3.21 The Outline layer simply helps you see the edge of the stage from inside the Content symbol.

Here’s where you can get creative. We’ll create a graphic or an animation to correspond with each of the phrases the nice young man says. Open the file imagesTemplate.fla in the finished_source folder and investigate the contents of the Content symbol to see how I created the sequence you’re about to create.

Create a new layer for the still images; name this new layer Stills. Insert a keyframe into frame 2 (press F6), and then import a photograph or create a graphic to support the phrase circumscribed clientele, such as a circle around a drawing of a student from the ‘60s. Click frame 3 and then select Insert, Timeline, Blank Keyframe (or press F7). Insert a graphic to support the word cool. In frame 4, insert a blank keyframe and place the following text: Derogatorily. To animate the international "no" sign on top of it, select Insert, Timeline, Layer (name the layer No sign). In the No sign layer, click frame 5 and insert a blank keyframe (press F7). Draw a circle with a line through it, convert the circle to a movie clip by selecting it and pressing F8, and name it no. In frame 10 of the No sign layer, insert a keyframe. Open the Actions panel and type stop();, and in frame 11 of the No sign layer, insert a blank keyframe (F7). Return to frame 5 and, using the Properties panel, select Motion Tween. Then, select the no symbol onstage in frame 5 and use the Properties panel to set a Color style of Alpha to 1%. (The no sign will fade on from frame 5 to frame 10.)

For the two mentions of the word swinging, we’ll show a graphic of a swing and then show that swing in motion. In frame 11, draw the swing. Next, in frame 12, start an animation of that swing that continues to frame 20, where you’ll place a keyframe and a stop() action.

For the last two phrases (coffee house and place to be and the place to be seen), just place a photo or logo from your favorite coffee shop (in frame 21) and the text be and be seen in frame 22.

Step 4: Gathering the Cue Points

Open gathering_tool.swf and enter the path to coffee_house_1969.flv into the Media field—don’t worry about loading captions this time. Play the video and click the Add button each time the man says one of the previous phrases. You can remove cue points you added by mistake by clicking their triangles and then clicking the Remove button. Each cue point’s name defaults to New Cue Point. Go through the added cue points by clicking each triangle or clicking the Prev or Next button; then enter a simple name for each one, such as Circumscribed, Cool, and so on. The user won’t ever see this text the way we’re building this project, but it helps to confirm that the cue points are in the right place.

When the cue points are in place, we’ll add parameters to each one, such as a frame number and an option of whether the animation should stop there or play. I came up with the idea that each cue point will have parameters for frame (the frame number to jump to in the Content symbol) and option (either play or stop meaning that when the user jumps to the frame, it will begin to play or simply stop there). Click the first cue point and click the plus button to add a parameter. Set the name to frame and the value to 2. This means when this cue point is reached, we’ll jump to frame 2 in the Content symbol, where the "Circumscribed Clientele" graphic appears. Click the plus button again and name the second parameter option; then set the value to stop (see Figure 3.22). The plan is that, when the user jumps to that frame, it will stop there.

Go through all the cue points so each one has parameters for name and option, as shown in the following table:

Name

Parameters

 

Circumscribed

frame option

2 stop

Cool

frame option

3 stop

Derogatorily

frame option

4 play

Swinging (1)

frame option

11 stop

Swinging (2)

frame option

12 play

Coffeehouse

frame option

21 stop

Place to be

frame option

22 stop

After you have all the cue points and parameters set, click the Export XML button. Copy the XML string that appears and create a new text document with Notepad or a similar program. Next, paste in the XML text you copied and save the file as coffee_house.xml in your working directory.

Figure 3.22

Figure 3.22 This cue point has two parameters: frame (2) and option (stop).

Step 5: Implementing the ActionScript in imagesTemplate.fla

Go to the main timeline of imagesTemplate.fla. Drag an instance of the Content symbol onto the stage if you haven’t done so already. (It might be a bit tricky considering nothing is in the first frame of the Content symbol.) Use the Properties panel to set the instance name to content and the upper-left corner to 0, 0.

Select the first keyframe, open the Actions panel, and type the code in Listing 3.6.

Notice that we completely ignore the first parameter received in showText() (that is, name). Instead, the code digs into wholeObject, which includes all the same properties that would be received from a standard cuePoint event. In this case, these properties are type, target, and info—inside of which are properties for name, time, and parameters (which itself contains whatever properties you injected into the .flv file or specified in the XML file). Here the code just grabs info.parameters.frame and info.parameters.option.

Step 6: Entering the ActionScript in main_coffee.fla

Inside main_coffee.fla, be sure you have an FLVPlayback component onstage; if not, drag one from the Components panel. Give it an instance name of playback.

Listing 3.6 This Code Handles New Captions by Jumping to the Appropriate Frame in the content Instance

function clear(){
  content.gotoAndStop(1);
}
clear();

function showText(name:String, wholeObject:Object, speed:String){
  content.gotoAndStop(wholeObject.info.parameters.frame);

  if( wholeObject.info.parameters.option == "play" ){
   content.play();
  }
}

function getSize():Object{
  return { width:250, height:250 };
}

Copy a CaptionHolder symbol from one of the other main files you’ve created (main.fla or main_audio.fla). Or simply select Insert, New Symbol and set the Create New Symbol dialog box as was shown previously in Figure 3.13 (step 2 of the fourth project). Place an instance of the CaptionHolder symbol onstage and give it an instance name of captions_clip. Arrange the screen so captions_clip is next to the video and not on top of it. The 320 x 50 rectangle shape in the CaptionHolder symbol is not an accurate representation of where the imagesTemplate.swf will appear because that file is actually 250 x 250. You can double-click the CaptionHolder and double-click again so you’re inside the Rectangle symbol and then resize that shape to make it 250 x 250. Back in the main timeline, you should select Modify, Document and increase the main_coffee.fla file’s width to at least 600 so the FLVPlayback component (instance name playback) and the CaptionHolder symbol (instance name captions_clip) fit side-by-side, as shown in Figure 3.23.

Finally, select the first keyframe, open the Actions panel, and type in the code in Listing 3.7.

Figure 3.23

Figure 3.23 The FLVPlayback (left) and CaptionHolder (right) are arranged side-by-side.

Listing 3.7 This Code Associates an Instance of theEventChannel Class with theimagesTemplate.swf File

var playback:mx.video.FLVPlayback;
playback.autoPlay = false;
playback.contentPath = "coffee_house_1969.flv";

var myEventChannel:EventChannel = new EventChannel();

//send init() function to the CaptionHolder instance 
//on stage (captions_clip)

var url = "imagesTemplate.swf";
var eventList = ["actionscript"];
captions_clip.init( url, myEventChannel, eventList );

//alternative code to effectively turn the FLVPlayback 
//into autoPlay=true
function ready(){
  playback.play();
}
myEventChannel.addEventListener( "ready", this );
myEventChannel.init( playback, "coffee_house.xml" );

This code should look very familiar—the only changes are the filenames for the .flv, imagesTemplate.swf, and .xml files.

Step 7: Testing main_coffee.fla

Make sure all the following support files are present in the same folder where your main_coffee.fla file is:

  • coffee_house_1969.flv
  • coffee_house.xml
  • imagesTemplate.swf
  • CaptionHolder.as
  • EventChannel.as

That folder should also contain the FLVPlayback skin you selected, such as MojaveOverNoVol.swf.

In main_coffee.fla select Control, Test Movie.

I hope that this template shows you another way to use cue points for more than just captions and also gives you the ability to design and build additional template types. Like many projects in this book, extra templates are available for download; plus, I expect readers to share their templates.

  • + Share This
  • 🔖 Save To Your Account