Setting a Source Video File
Next you will create ActionScript using a code snippet that loads and plays an external .flv video file into the FLVPlayback component when the page2_mc clip is clicked. The previous two code snippets that you added worked correctly without modifying the code at all. Often, however, you will need to make some adjustments to the ActionScript created by a code snippet to get it to do what you want. The code snippets that ship with Flash CS5 offer helpful comments that provide instruction on how to make changes to the code.
- On the Flash stage, select the page2_mc clip.
- In the Code Snippets panel, open the Audio and Video folder.
- Double-click the “Click to Set Video Source” Snippet. In the Actions panel below the previous code that was added, the code in Figure 3 will be inserted.
- Locate the line of code that reads:
- Alter this code to read:
- Test the movie. When you click the page2_mc tab, the water.flv video clip should download from http://www.helpexamples.com and play. If you have your own flash video files in the .flv or .f4v formats, you could modify the code to set the source path, and your video files will play instead.
- Close the codesnippets_start.swf file to leave the Flash testing environment and return to the authoring environment.
The code that is in gray contains ActionScript comments. Comments have no functionality but instead are typically used to make notes that can be helpful to the programmer or others reading their code. Multiline comments in ActionScript are contained within the forward slash-asterisk (/*) and asterisk – forward slash (*/) characters. Adobe includes many comments in its code snippets to help you understand and modify the ActionScript that the code snippet creates. The code snippet you just added contains instructions that explain how to customize the code.
As explained in Step 1, you will alter the code so that a loaded video file plays in the FLVPlayback component in the page2_mc movie clip.
video_instance_name.source = "http://www.helpexamples.com/flash/video/water.flv";
page2_mc.vidPlayer.source = "http://www.helpexamples.com/flash/video/water.flv";