Task 8: Playing an In-line Video Clip
In the past, Flash has had the ability to utilize QuickTime video, as long as the Flash movie itself was exported to QuickTime format (and played back by Apple's QuickTime Player). An approximation of streaming SWF video is available using third-party programs such as Wildform Flix, but those require an additional investment of funds. And while dedicated video platforms like Windows Media can be used for short video clips, they're often an inflexible solution.
Flash MX Solution
In addition to QuickTime video "linking," Flash MX supports video "embedding." Embedded video can be imported from a number of different formats (including .MOV, .DV, and .MPEG), and is compressed into a regular SWF movie along with your animation. You are limited to a couple of minutes of full-motion video per movie, but for most sites this is ample. Embedded video is compressed using the proprietary Sorenson Spark codec, designed for highly optimized streaming.
Flash videos can be controlled with ActionScript, masked, subtitled, and mixed with animation in ways that Windows Media or RealMedia clips cannot.
Try It
To add a Flash video clip with simple control buttons, complete the following steps:
Find a video clip in any format that Flash supports. Consult the documentation regarding formats, as support is dependent on whether you have the latest QuickTime or DirectX version installed.
Open a new Flash document, and use the File, Import to Library command to import the selected video clip. A Sorenson Spark options dialog box will appear, with various settings. If this is your first time embedding video, stick with the defaults. Otherwise tailor the settings for a good mix of efficiency and quality.
Click OK, and wait for the video to be recompressed into Spark format. This may take a few minutes. When the compression process is finished, the video clip will be available as a symbol in the Library (don't do anything with it yet, though).
Use the Insert menu to create a new Movie Clip symbol named VideoClip. You should be automatically taken into symbol editing mode.
Select the first frame of the timeline, and use the Actions panel to assign the following code:
stop();
This will prevent the video from playing back automatically.
Open the Library window and drag an instance of the video symbol onto the stage. A dialog will appear asking whether you want to insert x number of frames; click Yes.
Return to the main timeline, and then drag an instance of VideoClip onto the stage. Use the Properties inspector to give it the instance name VideoClip, for the sake of simplicity. The clip is now ready to be controlled with ActionScript.
Set up two control buttons by accessing the Window, Common Libraries, Buttons.fla file, and dragging out instances of "playback play" and "playback rewind" from the folder marked Playback.
Select the play button first, and use the Actions panel to assign the following code:
on (release) { VideoClip.play(); }
Select the rewind button and assign the following code:
on (release) { VideoClip.gotoAndStop(1); }
By sending the clip back to the first frame, the video is effectively "rewound."
When the movie is exported, the buttons will control the behavior of the VideoClip instance. Additional controls like Stop, Fast Forward, etc. can also be created using simple ActionScript commands.