17 March 2008
This article is geared towards beginning Flash users and developers who are interested in working with a simple video navigation template. While programming experience is not necessary to understand the tutorial, you may find it beneficial to review the Flash Video Learning Guide.
Intermediate
This Flash template is great for basic video presentations—situations when you want the user to see the main topics of a video and be able to navigate quickly to them. It does not contain some of the more sophisticated features, such as synchronizing content on the screen with the video playback, as described in my other tutorial, Spokesperson presentation with synchronized graphics. However, you should have little trouble modifying this template to work well for your own purposes.
The Flash video template provided with this article provides you with the basis of a navigational system for user-initiated playback of video clips (see Figure 1). Before beginning this tutorial, preview the online example of the Flash video template to explore how it works.
This is the third version of the Flash video template. Although the video dates from the Macromedia days, this article has been updated to work with the new Adobe Flash CS3 Professional FLVPlayback component and ActionScript 3.0. The updated template is built on a standard Timeline in Flash and has been simplified for easier editing and customization. The template features a video with playback controls, as well as navigation buttons, which allow the user to jump to specific topics within the video.
Consider applying the following special touches to bring this presentation to life in your company:
You can easily change this template to fit your needs.
This article describes how to modify all the basic characteristics so your project looks as desired. For example, you will certainly want to add your own video to this presentation. After swapping the video source, you can update the button text that provides navigation to the presentation. Finally, you can change the color schemes and logos to match your own designs and collateral materials.
Note: If you are still using Flash Professional 8, please see the previous version of this article.
In this version of the template, the content is distributed on layers on the main Timeline. This simplifies the customization process and provides easy access to all the editable features in a single location. Take a quick look at the main Timeline of the Flash video template (see Figure 2).
Notice that there is only one frame in the Timeline. The content structure is organized into five layers:
While you're browsing through the file, open the Library panel (Window > Library) and take a look at its contents (see Figure 3).
Notice the CueNameButton movie clip in the Skins folder. This symbol is used for the navigation buttons, which sit to the left of the video display. The second is the VideoFrame movie clip, which creates the background for the video display. Most of the other symbols are gathered from the Components inspector in Flash CS3 Professional.
Note: The FLV Playback Skins folder contains customizable skin graphics for each of the video controls.
There are two places where ActionScript appears in the template: Frame 1 of the main Timeline and Frame 1 of the CueNameButton timeline. You will make some minor edits to the actions on the main Timeline, but you will not need to edit the button's code. The updates to ActionScript 3.0 are minor, but are different enough that they merit some explanation.
The following code appears on the Actions layer on the main Timeline:
import flash.events.*;
import fl.video.*;
//-----------------
// Video control assignment
//-----------------
// Use the skin assignment properties of the FLVPlayback
// instance to associate the controls with the player.
display.playPauseButton = play_btn;
display.stopButton = stop_btn;
display.seekBar = seek_bar;
display.volumeBar = volume_bar;
display.muteButton = mute_btn;
display.fullScreenButton = full_btn;
//-----------------
// Video event handling
//-----------------
// Create an event handler function to find
// the nearest cuePoint to the end seek time
function scrubHandler( event:VideoEvent ):void
{
var cue = display.findNearestCuePoint(event.playheadTime);
navigate(cue.name, false);
}
display.addEventListener(VideoEvent.SCRUB_FINISH, scrubHandler);
// Create an event handler function to catch the
// cue event from the FLVPlayback instance.
function cuePointHandler( event:MetadataEvent ):void
{
// On cuePoint, look for a button named with the cue name
// plus "_btn". If it exists, then call its select method...
navigate(event.info.name, false);
}
display.addEventListener(MetadataEvent.CUE_POINT, cuePointHandler);
//-----------------
// Navigation / screen state
//-----------------
// Store the current button name
var currentBtn:*;
var currentBtnName:String = "";
function navigate( cueName:String, seekTo:Boolean ):void
{
// Handle previous button
var prev = getChildByName(currentBtnName);
if( prev != null ){
currentBtn.reset();
}
// Handle new button
var next = getChildByName(cueName+"_btn");
if( next != null ){
currentBtn = next;
currentBtn.select();
currentBtnName = cueName+"_btn";
}
// Seek to Cue Name
if( seekTo == true ){
var c = display.findCuePoint(cueName);
if( c != null ){
display.seekSeconds(c.time);
}
}
}
//-----------------
// Button event handling
//-----------------
// introduction_btn
function introductionHandler( event:MouseEvent ):void
{
navigate("introduction", true);
}
introduction_btn.addEventListener(MouseEvent.CLICK, introductionHandler);
// overview_btn
function overviewHandler( event:MouseEvent ):void
{
navigate("overview", true);
}
overview_btn.addEventListener(MouseEvent.CLICK, overviewHandler);
// aim_btn
function aimHandler( event:MouseEvent ):void
{
navigate("aim", true);
}
aim_btn.addEventListener(MouseEvent.CLICK, aimHandler);
// formats_btn
function formatsHandler( event:MouseEvent ):void
{
navigate("formats", true);
}
formats_btn.addEventListener(MouseEvent.CLICK, formatsHandler);
// summary_btn
function summaryHandler( event:MouseEvent ):void
{
navigate("summary", true);
}
summary_btn.addEventListener(MouseEvent.CLICK, summaryHandler);
Note: The only part of this code that you will edit will be the mouse event handlers at the bottom. You will add and remove mouse event handlers to match the buttons and cue points in your movie.
The following code appears on the Actions layer on the CueNameButton timeline:
import flash.events.MouseEvent;
//-----------------
// Variables
//-----------------
var current:Boolean = false;
//-----------------
// Selection from an outside source
//-----------------
function select():void
{
current = true;
gotoAndStop("down");
}
function reset():void
{
current = false;
gotoAndStop("up");
}
//-----------------
// Mouse events
//-----------------
// rollOver
function rollOverHandler(event:MouseEvent):void{
if(!current){
gotoAndStop("over");
}
}
// rollOut
function rollOutHandler(event:MouseEvent):void{
if(!current){
gotoAndStop("up");
}
}
addEventListener(MouseEvent.ROLL_OVER, rollOverHandler);
addEventListener(MouseEvent.ROLL_OUT, rollOutHandler);
Note: The code above shows how to make a movie clip into a button in ActionScript 3.0. The button listens for its own mouse events and navigates to labeled frames in the Timeline to show button state graphics.
The FLVPlayback component displays the video in the template (see Figure 4). You will select the FLVPlayback instance on the Stage to change the layout and parameters of the video. You can change the following items to customize the display:
The video component in Figure 4 appears as a black rectangle with the Flash video icon in the center. When you select the instance, a blue bounding box surrounds it. The parameters for the video component can be set in the Property inspector or in the Component inspector. Also notice that the custom video controls (play, stop, seek bar, volume bar, mute button, and full-screen button) are separate controls and are not attached to the FLVPlayback instance. (You will explore changes to these controls in the section "Modifying the buttons and video controls".)
To change the video and FLVPlayback parameters:
source field to select it and then click it again to launch the Content Path dialog box (see Figure 5).
Notice that you have an option to match the FLV dimensions. This is a great feature that lets the video component size itself to the target video. If you enter an absolute path into the field, the Download FLV for Cue Points and Dimensions check box becomes active.
For more information on FLVPlayback component parameters, refer to the Flash CS3 LiveDocs (Using ActionScript 3.0 Components > Using the FLVPlayback component > FLVPlayback component parameters).
Note that the FLVPlayback component uses embedded metadata in the FLV file to determine the size and duration of the video for automated features such as "Match source FLV dimensions." If you are trying to use an older FLV file that does not contain this metadata, you may notice that some of these features do not work. If this is the case, your best bet is to encode the original video to the FLV format again using the Flash CS3 Video Encoder or use a utility to embed the metadata in the older FLV file.
To change the layout of the video component, you can either let the component automatically size itself to the target FLV file or you can manually change the size the component on the Stage.
If you want the component to size itself automatically, follow the steps in the previous section for assigning the source parameter and make sure you select the Match Source FLV Dimensions check box. Selecting this option will cause the video component to automatically match your FLV file on the Stage, making it easy for you to position the video as desired.
To size the video instance manually, follow these steps:
scaleMode field to maintainAspectRatio in the parameter list. These parameters affect the component when the SWF file is playing. Turning off the parameters enables the video to be displayed at any size you choose.scaleMode parameter to adjust how the video appears in the custom size view.To move the video to a new location, follow these steps:
The navigation buttons appearing along the left side of the video display are a key feature of the template. These buttons enable users to jump to predefined sections (topics) within the video. The navigation buttons label each section of the video and enable users to understand the content of the movie and how to seek to any topic desired. In this next section of the article, you'll learn how to do the following:
Before you jump into editing the navigation buttons, it's important to understand what is happening with the video component that makes this all work. The big picture is that you can assign sections in each FLV file that can be used for navigation and synchronization. These sections are called cue points. You can add them to the video when it is initially encoded to the FLV format (the preferred method) by using the cuePoints field in the FLVPlayback parameters or by using ActionScript while the SWF file plays. For this demonstration, I will explore adding and removing cue points using the Flash Video Cue Points dialog box (see Figure 6).
As you can see, named cue points can be added to each video to create sections within the video. Cue points have an associated time within the video and may also contain other data that can be referenced as cue points are encountered along the video timeline.
To change, add, or remove cue points, follow these steps:
cuePoints parameter once to select it and then click it again to launch the Flash Video Cue Points dialog box.That's it. After you add your own video to the FLVPlayback component, you will adjust the cue points to match the sections of your video. You can use as many or as few cue points as you want. From there, you will update the navigation buttons to match the cue point entries.
Tip: Embedding navigation cue points during encoding is more accurate than using the Flash Video Cue Points dialog box. If you are having problems with the accuracy of seeking to exact cue point times, consider encoding the video and cue points together using the Flash CS3 Video Encoder instead.
As you view the template in action, you'll notice that the down state for each button appears when the video plays past the related cue point. This template uses a naming convention to find the navigation button when a cuePoint event fires from the video component. The Actions layer contains an event handler function which processes cuePoint events.
When a cue point event occurs, the function looks for a button whose instance name matches the cue point name plus the letters "_btn". If a button exists, it triggers the button to show its down state. For example, if a cue point event named introduction passes through the event handler function, then the button whose instance name is introduction_btn is highlighted with its down state. There's no need to adjust any of the code; simply create cue points and name the corresponding buttons with the cue point name plus "_btn".
The Buttons layer contains five instances of the CueNameButton with static text typed over the instances to create the button labels.
To change the text on a navigation button:
The CueNameButton symbol uses a scaling feature called 9-slice scaling. This enables the button to be scaled from instance to instance without seeing the effects of distortion common to most scaled movie clips. The template provides a simple button skin with an up, over, and down state that you can customize to fit your needs. You will edit your graphics in the Library and use the scale guides to control how Flash renders your graphics at different sizes (see Figure 8).
You can move and resize the navigation buttons in any way you desire. To edit the up, over, and down button skins, follow these steps:
To remove a navigation button, simply select the button instance and the text on top of it and delete the two items from the Stage.
You have two options when adding a navigation button to your file. You can either drag a new instance of the CueNameButton symbol from the Library to the Stage or copy an existing button.
To add a new navigation button and associated cue point, follow these steps:
To trigger a cue point change from a new button:
// conclusion_btn
function conclusionHandler( event:MouseEvent ):void
{
navigate("conclusion", true);
}
conclusion _btn.addEventListener(MouseEvent.CLICK, conclusionHandler);
That's it. Your new navigation button should trigger the video to jump to the corresponding cue point.
Note: You cannot place code directly on a button instance in ActionScript 3.0. The process used in this sample is the approach to use to respond to button clicks in ActionScript 3.0 files.
The template contains a basic set of video controls, including a play/pause button, stop button, seek bar, volume bar, mute button, and a full-screen button. These controls are placed on the FLVPlayback layer alongside the FLVPlayback instance. The controls are associated with the FLVPlayback instance using a small amount of ActionScript code on the Actions layer.
You can remove any or all of the controls without making other adjustments to the template. If you want to insert additional custom user interface components, you will need to name their instances and update the code on the Actions layer to associate them with the video component.
To remove all the user interface controls, follow these steps:
//-----------------
// Video control assignment
//-----------------
// Use the skin assignment properties of the FLVPlayback
// instance to associate the controls with the player.
display.playPauseButton = play_btn;
display.stopButton = stop_btn;
display.seekBar = seek_bar;
display.volumeBar = volume_bar;
display.muteButton = mute_btn;
display.fullScreenButton = full_btn;
You may add any combination of FLVPlayback custom user interface controls by dragging instances from the Components panel to the Stage. You must name the instance and assign the instance name to the FLVPlayback instance using assignment properties as seen in the code above.
To add a buffering bar, follow these steps:
// Assign the buffering bar to the video component
display.bufferingBar = bufferingBar_mc;
The FLVPlayback component has a handful of control assignment properties that you can use in a similar way as described above to assign the other types of controls to the video component. The property list includes the following:
playButtonpauseButtonplayPauseButtonstopButtonmuteButtonbackButtonforwardButtonvolumeBarseekBarbufferingBarfullScreenButtonYou can customize the FLVPlayback controls easily to match whatever look and feel you need. For this template I changed the green highlight color to red to match the video theme better. See my article, Skinning the ActionScript 3.0 FLVPlayback component, for more information on skinning options.
Note: The full-screen mode and its related button are new features in Flash CS3 Professional. To use the feature, make sure you publish your Flash movie using the Enable Full Screen HTML template.
One of the easiest changes to make to the template involves making modifications to the look and feel of the background graphics. Changing the color of the chrome (gradient) graphics in the background can really go a long way towards creating a unique-looking template that fits your company's branding and tone. Simple changes to the template may include:
As you've seen in previous sections of this article, the playback component is separate from the video controls. This makes customizations easy by enabling you to move the controls to any location, swap different types of video controls in and out of the template, and use any background graphic you like. For the purposes of this template, I created a simple custom background inside the VideoFrame symbol in the Library (see Figure 10).
To edit the video background graphic, follow these steps:
This is the easy part. Edit the graphics contained in the Background layer (see Figure 11) to change the background. You can add and remove graphics as desired.
To change the background graphic and logo, follow these steps:
Now that you have customized the template and made the presentation your own, there are many ways to update it to target your audience and make your presentation more immersive. Possible customizations include the following:
Make sure to also explore the other Flash video templates provided in the Flash Developer Center.
| 04/23/2012 | Auto-Save and Auto-Recovery |
|---|---|
| 04/23/2012 | Open hyperlinks in new window/tab/pop-up ? |
| 04/21/2012 | PNG transparencies glitched |
| 04/01/2010 | Workaround for JSFL shape selection bug? |
| 02/13/2012 | Randomize an array |
|---|---|
| 02/11/2012 | How to create a Facebook fan page with Flash |
| 02/08/2012 | Digital Clock |
| 01/18/2012 | Recording webcam video & audio in a flv file on local drive |