| Video and Media Components 2 |
| notes for Flash 7 Pro only |
This is a continuation from Video and Media Components, part 1.
In part 2, we will be looking at using the video editing capabilities available during import; exporting Flash videos in the FLV file format; working with the local Embedded Video object, and a quick look at the MediaPlayback component.
In Video and Media Components, part 3, we look at using the Media Components to load and control playback of FLV (and MP3) files, and some basic scripting for when greater control is required.
While the video editing capabilities of Flash are minimal, they do allow the author an easy way to trim video clips of unwanted false starts, throat-clearing, and other content artifacts without having to open up a separate video editor. Final Cut this is not ... it's Flash, after all ... but even just the ability to set in and out points can speed up your workflow.
video_clip.mov on a Mac; video_clip.avi on a Win
Navigate to and select the video_clip file appropropriate to your platform
If you have imported a Quicktime file, click: Next



The editing screen/panel's left portion contains the clip library ... where you can store and sequence any clips you create. The right section contains the preview area, in and out point controls, and playback controls.
The talking head speaks about three things to consider when working with Flash, two of which are meaningful. In this first exercise, we will simply trim off the second or so of dead air at the beginning of the clip and at the ending of the clip.
The left-most and right-most arrows do not affect playback ... instead, they move the In and Out points to the current position of the playback head.
The inner four controls backstep, play, stop, and step forward through the clip.

The white area on each end represents the part of the video which will be trimmed; the blue part indicates what will be included. The yellow downward pointing arrow above the timeline is the playback head. The white half-triangles below are the in and out points.
With the in and out points set, the Preview clip button will play just the part between the in and out points.
This extracts a clip from the imported video, and places it in this panel's library list:

This takes us back to the Compression and Advanced settings part of the video import wizard
The talking head wants to look good
You may use these suggested settings, or experiment to improve on them ...
Now we have an opportunity to work with scaling and cropping the margins:
Because of the aspect ratio of the camera, the video's dimensions started at 720 x 480. Let's shoot for 320 x 240 as our final clip size.
At 50% scaling, this takes us to 360 x 240 ... we would like to crop 20 pixels from each side
No, that is not a mistake: we do in fact want to crop 20 pixels from the left and 20 pixels from the right.
However, we are also scaling this clip, and the cropping is done before the scaling. So if we want to end up with a width of 320 after scaling the original by 50%, then we need to start with a width of 640. If the original video was 720 pixels wide (why does this all of a sudden sound like one of those horrible word math problems?), we need to crop a total of 80 pixels before we scale it ... 40 pixels from the left, and 40 pixels from the right.
We can see why the Quick Encode option was included ...
We are asked this because we elected to Import this video into a movie clip ...
We should see our target size of 320 x 240
Looking at the results, we can see that the little bit of color correction helped.
We can also determine that the compression settings were on the over-generous side: we didn't really need that higher bandwidth setting.
Since the content is a talking head, we didn't really need about two-thirds of the total image ... who really cares about the poster in the background, or Audrey the plant ... . The next time, we could scale even smaller, and be more agressive in our cropping.
Next, let's chop up the imported video, and resequence the list of important things to consider, so instead of them being presented 1, 2, and then goofy 3, we'll present them in reverse order.
video_clip.mov on a Mac; video_clip.avi on a Win
Navigate to and select the video_clip file appropropriate to your platform
We want to end up with four separate clips: the introduction, step1, step2, and step3
Use the playback controls to visually establish where the following sentence is located:
"There are three things to consider when working with video in Flash."
The starting/In timecode is approximately 1.583, and the ending/Out timecode is approximately 6.721
There are several ways in which you can set the In and Out point markers (the half-triangles beneath blue horizontal clip timeline indicator): (1) you can simply drag each marker into position; (2) you can scrub (drag) the playback head above the timeline indicator back and forth to visually establish an In/Out point, then drag the In/Out point indicator to that position; (3) work with the Play and Stop controls (and the Backstep and Forwardstep controls for fine-tuning) until the playback head is in position, and then use the Set In/Out point controls to jump the In or Out point indicator to the playback head's current position.
The blue area of the clip timeline has shrunk to between the In and Out points
The clip library area now has a clip with the original name of the imported video

Use the playback controls to visually establish where the following sentence is located:
"One: work with uncompressed video and audio."
The starting/In timecode is approximately 7.488, and the ending/Out timecode is approximately 13.628 - the timecodes specified here are only for your visual reference
Note: Once a single clip has been added to the clip library, the editing screen becomes focused on the selected clip. When creating a subsequent clip, you might find it easier to set the In and Out points with the Set In/Out point buttons at either end of the playback controls.
The blue area of the clip timeline has shrunk to between the In and Out points
The clip library area now has a clip with the original name of the imported video
Use the playback controls to visually establish where the following sentence is located:
"Two: do all of your major editing outside of Flash, in a standalone application."
The starting/In timecode is approximately 14.396, and the ending/Out timecode is approximately 21.566
The clip library area now has a clip with the original name of the imported video
Use the playback controls to visually establish where the following sentence is located:
"Three: don't forget to smile."
The starting/In timecode is approximately 22.103, and the ending/Out timecode is approximately 26.140
The clip library area now has a clip with the original name of the imported video
Note: If we had wanted to rearrange the order of the four clips, we could have used the up/down arrows to change the order in the library/list, and then selected the Combining checkbox. This will create a single Embedded Video asset in the library.
We're done creating the individual clips, and you should now be at the Encoding/Settings screen
This will allow us to compare the results from that of the previous exercise.
These are the same settings we established for the previous example
It will appear as if four separate video files are being imported: in fact, Flash is only importing the four sections/clips we defined earlier (Introduction, Step1, Step2, and Step3).
You should see four embedded video assets in the library, each named after the clip we defined upon import (Introduction, Step1, Step2, and Step3). These embedded video assets behave pretty much like Graphic symbols: their playback is wedded/synchronized to the playback of whichever timeline they are located upon.
What this means is that if you drag an instance of an embedded video asset onto the main timeline/stage, it will play back in sync with the main movie's timeline: stop the main movie timeline and you stop the video instance.
If you want independent playback of the video, place the embedded video asset inside of a movie clip, and place the movie clip instance on the stage. Since movie clip timelines are independent of the main movie timeline, you would now have independent control of the playback of the movie and the embedded video.
The remainder of this exercise is designed to explore different ways in which video can be used in and with Flash ... the end result is not meant to make sense as a completed project. Instead, the journey through the next steps is meant to explore different ways of working with video.
Flash is intelligent enough to ask if you want to extend the layer containing the video, so as to display the entire video
You can drag or align the video instance, and it's new position will be reflected in all of the other frames on that layer
To control playback of an embedded video placed on the main timeline, use the traditional ActionScript to stop and play the main timline:
You can grab four from the Common Library of Buttons (any four will do, including gel Rewind, gel Stop, and gel Right from the Playback folder, and Circle with Arrow from the Circle Buttons folder)
rewind_btn
stop_btn
play_btn
next_btn
rewind_btn.onRelease = function () {
gotoAndStop(1);
}
stop_btn.onRelease = function () {
stop();
}
play_btn.onRelease = function () {
play();
}
next_btn.onRelease = function () {
nextScene();
}
stop();
gotoAndStop(1);
Controlling the playback of an embedded video placed on the main timeline is simply a matter of controlling the playback of the main timeline
You can drag or align the video instance, and it's new position will be reflected in all of the other frames on that layer
stop();
To control playback of an embedded video placed inside of a movie clip, use the traditional ActionScript to stop and play the movie clip:
You can grab four from the Common Library of Buttons (any four will do, including gel Rewind, gel Stop, and gel Right from the Playback folder, and Circle with Arrow from the Circle Buttons folder). You can re-use the Circle with Arrow by dragging a second instance onto the stage, and flipping it horizontally or rotating it by 180°
rewindmc_btn
stopmc_btn
playmc_btn
prev_btn
next_btn
rewindmc_btn.onRelease = function () {
step3_mc.gotoAndStop(1);
}
stopmc_btn.onRelease = function () {
step3_mc.stop();
}
playmc_btn.onRelease = function () {
step3_mc.play();
}
prev_btn.onRelease = function () {
prevScene();
}
next_btn.onRelease = function () {
nextScene();
}
stop();
Controlling the playback of an embedded video placed in a movie clip is simply a matter of controlling the playback of the movie clip.
In the next example, we will create an empty Embedded Video object (sometimes referred to as a "Local Video Object"), and then dynamically (by means of ActionScript) associate ("attach") an external FLV during runtime.
An FLV file is a Flash Video file which can be progressively downloaded (streamed) without the need of any special streaming server software, and uses regular old HTTP to access
The italicized"i" in the blue circle at the bottom of the Library panel
... to dismiss the Embedded Video Properties dialog box
You can grab five from the Common Library of Buttons (any five will do, including gel Rewind, gel Stop, and gel Right from the Playback folder; Playback - Loop also from the Playback folder; and Circle with Arrow from the Circle Buttons folder). You can re-use the Circle with Arrow by dragging a second instance onto the stage, and flipping it horizontally or rotating it by 180°
rewindVideo_btn
stopVideo_btn
playVideo_btn
attachVideo_btn
prev_btn
next_btn
prev_btn.onRelease = function () {
prevScene();
}
next_btn.onRelease = function () {
nextScene();
}
stop();
This provides us with the basic movie navigating controls
This creates an empty Embedded Video asset in the Library with the default name: Embedded Video 1
var my_nc = new NetConnection();
my_nc.connect(null);
var step2_ns = new NetStream(my_nc);
step2_ns.onStatus = function (infoObject) {
if(infoObject.level.toLowerCase() == "error") {
// your own error handling code here
trace(infoObject.code);
}
}
step2_video.attachVideo(step2_ns);
step2_ns.play("step2.flv");
Explanation
// streaming an FLV through a local video object // provides mechanism for playing external FLVs var my_nc = new NetConnection(); // open local connection my_nc.connect(null); // we've established a connection; this controls the stream var step2_ns = new NetStream(my_nc); // can perform error checking step2_ns.onStatus = function (infoObject) { if(infoObject.level.toLowerCase() == "error") { // your own error handling code here trace(infoObject.code); } } // attach the NetStream instance with the video object step2_video.attachVideo(step2_ns); // start the stream step2_ns.play("step2.flv");
new NetConnection() NetConnection.connect(null)null establishes a local (http:// or file://) connection ... meaning, bypass any special server-side appication (Flashcom server)new NetStream(NetConnection_instance)NetStream.onStatus()level, which can have the string value "error" or "status"; code, which contains a status messageEmbeddedVideoInstance.attachVideo(NetStream_instance)NetStream.play("URL")If all went well, the external FLV should immediately begin playing in the embedded video instance, step2_video. If not, and there was a server- or file-related problem, the Output window should have a brief status message.
You can verify this by moving the step2.flv file out of the current folder, and Test Scene again. This time, the Output window should display a status message, like: "NetStream.Play.StreamNotFound". After testing, move the step2.flv file back into the current folder.
Frame actions are taken automatically when the playback head sweeps through the frame. Button actions are initiated by user input. To (progressively download and) play, all we need to do is put the play() statement within a button action.
step2_ns.play("step2.flv"); statement// start the stream // step2_ns.play("step2.flv"); attachVideo_btn.onRelease = function () { step2_ns.play("step2.flv"); }
Now the external FLV will only load and play when a user clicks on the attachVideo_btn button.
The frame 1 ActionScript so far:
// streaming an FLV through a local video object
var my_nc = new NetConnection();
my_nc.connect(null);
var step2_ns = new NetStream(my_nc);
step2_ns.onStatus = function (infoObject) {
if(infoObject.level.toLowerCase() == "error") {
trace(infoObject.code);
}
}
step2_video.attachVideo(step2_ns);
// start the stream
// step2_ns.play("step2.flv");
attachVideo_btn.onRelease = function () {
step2_ns.play("step2.flv");
}
prev_btn.onRelease = function () {
prevScene();
}
next_btn.onRelease = function () {
nextScene();
}
stop();
rewindVideo_btn.onRelease = function () {
step2_ns.seek(0);
step2_ns.pause(true);
}
stopVideo_btn.onRelease = function () {
step2_ns.pause(true);
}
playVideo_btn.onRelease = function () {
step2_ns.pause(false);
}
NetStream.seek(seconds) NetStream.pause() NetStream.pause(true) true is supplied as an argument, this pauses the stream.NetStream.pause(false) false is supplied as an argument, this resumes the stream. You should now be able to stop, start, and rewind the video stream, just as you could do similar things with an embedded video clip.
(In other contexts, whenever you leave that part of your presentation where you are no longer displaying the video)
prev_btn.onRelease = function () { prevScene(); step2_ns.close(); } next_btn.onRelease = function () { nextScene(); step2_ns.close(); }
// streaming an FLV through a local video object // provides mechanism for playing external FLVs var my_nc = new NetConnection(); // open local connection my_nc.connect(null); // we've established a connection; this controls the stream var step2_ns = new NetStream(my_nc); // can perform error checking step2_ns.onStatus = function (infoObject) { if(infoObject.level.toLowerCase() == "error") { // error handling code here trace(infoObject.code); } } // attach the NetStream instance with the video object step2_video.attachVideo(step2_ns); // start the stream // step2_ns.play("step2.flv"); // uncomment to stream automatically // start the stream attachVideo_btn.onRelease = function () { step2_ns.play("step2.flv"); } // control video stream "playback" rewindVideo_btn.onRelease = function () { step2_ns.seek(0); step2_ns.pause(true); } stopVideo_btn.onRelease = function () { step2_ns.pause(true); } playVideo_btn.onRelease = function () { step2_ns.pause(false); } // movie navigation prev_btn.onRelease = function () { prevScene(); step2_ns.close(); } next_btn.onRelease = function () { nextScene(); step2_ns.close(); } stop();
One way to avoid having to deal with this NetConnection/NetStream ActionScript is to work with the Media Components.
... to dismiss the Embedded Video Properties dialog box
You can grab the Circle with Arrow from the Circle Buttons folder, and flipping it horizontally or rotating it by 180°
prev_btn
prev_btn.onRelease = function () {
prevScene();
}
stop();
This provides us with the basic movie navigation controls
The Media Components provide an easy way to stream FLVs and MP3s, and control their playback, with a minimum of scripting. Of course, like with most components, you can gain much greater control over them if you need to, if you do control them with ActionScript.
First, let's explore how easy it is to use these components.
The MediaPlayback component is a combination of the MediaDisplay and MediaController components
The chrome around the display area is about 8 pixels on each side. Since our video clip is 320 x 240, the width of the component should be 320 + 8 + 8 = 336
The height of the clip is 240, so the height begins at 240 + 8 + 8 = 256
The control part of the MediaPlayback is about 70 pixels, so the final height is 256 + 70 = 326

In the Parameters tab:
If the FLV was created by the Flash Video Exporter, the FLV will have the appropriate metadata so that the Video Length field does not have to be filled in. For this component to function completely, the Video Length field does need to be set properly.
Here's a quick and dirty way to get that time:
on(change) {
trace(this.playheadTime);
}
We are sending the MediaPlayback component's current (playback head) time to the Output window
Look at the last entry in the Output window ... this is the length of your FLV. If testing with the step1.flv, the time should be around 6.166 seconds. But remember, you may have edited this clip much differently, so your time value should be different
Now that you have an actual value, enter the length that you determined
Video Length: 00: 00: 6: 166 (be sure to use your own value)
Select this option if you want the FLV to automatically play once enough of it has loaded
Select this option to preserve the height and width dimensions if the display area is larger than those dimensions. If the display area is smaller, the video will be scaled to the smaller size, even with this checkbox selected. This only prevents it from growing larger than it's original size.
This option only becomes available if the Preferred Media Size is deselected.
You have the option as to where to place the playback controls
On leaves the controls always visible, Off leaves the controls invisible (not available), and Auto makes them visible when the user cursors over the region the controls normally occupy
The bottom region of the Components Inspector (MediaPlayback) is for setting Cue Points, which can be used to trigger behaviors ... sort of like setting up your own triggering events.
If all went well, the FLV should be automatically loaded (and the background behind the progressbar should show the file as it is streaming); the playback head should be seen moving as the video plays out; the controls for pausing, playing, and rewinding should all be working.
And no ActionScript was necessary to make this component work!
In the first two parts of this tutorial, we looked at different ways in which video could be used within a Flash Project: imported and placed on the main timeline and imported and placed in a movie clip, and controlled by basic ActionScripting of the playback of the main timeline or a movie clip; imported and exported as an FLV, and then used as an external asset, loaded at runtime, and played back through a local embedded video instance or through Media Components. It was only the use of the (Flash 6 compatible) local Embedded Video object that required any special knowledge and use of ActionScript to enable and control playback.
However, should you need greater control over the MediaPlayback or other Media components:
Before we get started with the MediaPlayback component, let's first look at using the two other media components which make up the MediaPlayback.
Concluded in Video and Media Components, part 3 ...
completed as of Sunday, Apr 04, 12:45pm
| copyright© 2004 Stephen McManus | April 04, 2004 |
Not covered in this tutorial:
Combining the list of clips into a single library item:
This takes all of the clips in the list and combines them into a single Embedded Video asset in the Library
Reordering the clips:
The up and down arrows moves the selected clip in the library/list into a new position: the position determines it's order when combining the list of clips
Update clip:
When a clip is selected in the library/list, it's In and Out points can be modified. Once a new In and/or Out point is established, clicking on the Update clip button modifies the original In/Out points