One important capability of Adobe Flash Player is the ability to display and manipulate video information with ActionScript in the same way that you can manipulate other visual content such as images, animation, text, and so on.
When you create a Flash Video (FLV) file in Adobe Flash CS3 Professional, you have the option to select a skin for your video including common playback controls. However, there is no reason you need to limit yourself to the options available. Using ActionScript, you have fine-tuned control over loading, displaying, and controlling playback of video--meaning you could create your own video player skin, or use your video in any less traditional way that you want.
Working with video in ActionScript involves working with a combination of several classes:
Video class: The actual video content box on the Stage is an instance of the Video class. The Video class is a display object, so it can be manipulated using the same techniques that can be applied to other display objects, such as positioning, applying transformations, applying filters and blending modes, and so forth.
NetStream class: When you're loading a video file to be controlled by ActionScript, a NetStream instance is used to represent the source of the video content--in this case, a stream of video data. Using a NetStream instance also involves using a NetConnection object, which is the connection to the video file--like the tunnel that the video data is fed through.
Camera class: When you're working with video data from a camera connected to the user's computer, a Camera instance represents the source of the video content--the user's camera and the video data it makes available.
When you're loading external video, you can load the file from a standard web server for progressive download playback, or you can work with streaming video delivered by a specialized server such as Adobe's Macromedia® Flash® Media Server.
Common video tasks
This chapter describes the following video-related tasks that you will likely want to perform:
Displaying and controlling video on the screen
Loading external FLV files
Handling metadata and cue point information in a video file
Capturing and displaying video input from a user's camera
Important concepts and terms
Cue point: A marker that can be placed at a specific moment in time in a video file, for example to act like a bookmark for locating that point in time, or to provide additional data that is associated with that moment in time.
Encoding: The process of taking video data in one format and converting it to another video data format; for example, taking a high resolution source video and converting it to a format that's suitable for Internet delivery.
Frame: A single segment of video information; each frame is like a still image representing a snapshot of a moment in time. By playing frames in sequence at high speed, the illusion of motion is created.
Keyframe: A video frame which contains the full information for the frame. Other frames that follow a keyframe only contain information about how they differ from the keyframe, rather than containing the full frame's worth of information.
Metadata: Information about a video file that can be embedded within the video file and retrieved when the video has loaded.
Progressive download: When a video file is delivered from a standard web server, the video data is loaded using progressive download, meaning the video information loads in sequence. This has the benefit that the video can begin playing before the entire file is downloaded; however, it prevents you from jumping ahead to a part of the video that hasn't loaded.
Streaming: As an alternative to progressive download, a special video server can be used to deliver video over the Internet using a technique known as streaming (sometimes called "true streaming"). With streaming, the viewer's computer never downloads the entire video at one time. To speed up download times, at any moment the computer only needs a portion of the total video information. Because a special server controls the delivery of the video content, any part of the video can be accessed at any time, rather than needing to wait for it to download before accessing it.
Working through in-chapter examples
As you're working through the chapter, you may want to test some of the example code listings for yourself. Because this chapter is about working with video in ActionScript, many of the code listings in this chapter involve working with a video object, which could be one that has been created and placed on the Stage in Flash authoring, or one that's created using ActionScript. Testing a sample will involve viewing the result in Flash Player to see the effects of the code on the video.
Most of the example code listings manipulate a Video object without creating the object explicitly. To test these code listings in this chapter:
Create an empty Flash document.
Select a keyframe in the Timeline.
Open the Actions panel and copy the code listing into the Script pane.
If necessary, open the Library panel.
From the Library panel menu, choose New Video.
In the Video Properties dialog box, enter a name for the new video symbol, and choose Video (ActionScript-controlled) in the Type field. Click OK to create the Video symbol.
Drag an instance of your video symbol from the Library panel onto the Stage.
With the video instance selected, in the Property inspector, give it an instance name. The name should match the name used for the Video instance in the example code listing--for example, if the code listing manipulates a Video object named vid, you should name your Stage instance vid as well.
Run the program using Control > Test Movie.
On the screen you will see the results of the code manipulating the video as specified in the code listing.
Some example code listings in this chapter include a class definition in addition to the example code. In those listings, in addition to the previous steps, and before testing the SWF, you will need to create the class that's used in the example. To create a class defined in an example code listing:
Make sure you have saved the FLA file that will be used for testing.
From the main menu choose File > New.
In the New Document dialog, in the Type section, choose ActionScript File. Click OK to create the new ActionScript file.
Copy the class definition code from the example into the ActionScript document.
From the main menu, choose File > Save. Save the file in the same directory as the Flash document. The file's name should match the name of the class in the code listing. For instance, if the code listing defines a class named "VideoTest," save the ActionScript file as "VideoTest.as".
Return to the Flash document.
Run the program using Control > Test Movie.
You will see the results of the example displayed on the screen.