Build a Pre-roll Player for Ads, etc
Updated: Dec 19, 2007
Views: 5595
Description: This tutorial shows you how to automatically play a new movie after the initial one is complete.
Part I - The Completed Project
Good news! This is going to be really easy. All you need to do is use the FLV Player's complete event to determine when the first video finishes and then set the source to the next video. More advanced users may only need to look at this example, while others might want to read below where I will go through the code.
ActionScript
Part II - Setting Up the File
The file setup here is pretty straight-forward. Create a new Flash ActionScript 3.0 file and drag an instance of the FLV Player to the stage. Give it an instance name "myPlayer."
Note: Add the path to your first video in the source parameter for the player.

Next, create a new layer and name it "ActionScript." This is where you will place the code that plays the next video after the first one is complete.

Part III - The Code
Finally, lets step through the code.
Here, we use the player's complete event to set the source to a new video. If the player's autoPlay parameter is set to true, the new video will start playing as soon as it's buffered.
That's all there is to it. If you have any further questions, let us know on the forum. Enjoy!
Good news! This is going to be really easy. All you need to do is use the FLV Player's complete event to determine when the first video finishes and then set the source to the next video. More advanced users may only need to look at this example, while others might want to read below where I will go through the code.
ActionScript
import fl.video.VideoEvent;
function onPlayerComplete(event:VideoEvent) {
// remove listener so it doesn't happen again
myPlayer.removeEventListener(VideoEvent.COMPLETE, onPlayerComplete);
// set source to new video
myPlayer.source = "http://www.afcomponents.com/flv/vid/sample.flv";
}
myPlayer.addEventListener(VideoEvent.COMPLETE, onPlayerComplete);
function onPlayerComplete(event:VideoEvent) {
// remove listener so it doesn't happen again
myPlayer.removeEventListener(VideoEvent.COMPLETE, onPlayerComplete);
// set source to new video
myPlayer.source = "http://www.afcomponents.com/flv/vid/sample.flv";
}
myPlayer.addEventListener(VideoEvent.COMPLETE, onPlayerComplete);
Part II - Setting Up the File
The file setup here is pretty straight-forward. Create a new Flash ActionScript 3.0 file and drag an instance of the FLV Player to the stage. Give it an instance name "myPlayer."
Note: Add the path to your first video in the source parameter for the player.

Next, create a new layer and name it "ActionScript." This is where you will place the code that plays the next video after the first one is complete.

Part III - The Code
Finally, lets step through the code.
import fl.video.VideoEvent;
function onPlayerComplete(event:VideoEvent) {
// remove listener so it doesn't happen again
myPlayer.removeEventListener(VideoEvent.COMPLETE, onPlayerComplete);
// set source to new video
myPlayer.source = "http://www.afcomponents.com/flv/vid/sample.flv";
}
myPlayer.addEventListener(VideoEvent.COMPLETE, onPlayerComplete);
function onPlayerComplete(event:VideoEvent) {
// remove listener so it doesn't happen again
myPlayer.removeEventListener(VideoEvent.COMPLETE, onPlayerComplete);
// set source to new video
myPlayer.source = "http://www.afcomponents.com/flv/vid/sample.flv";
}
myPlayer.addEventListener(VideoEvent.COMPLETE, onPlayerComplete);
Here, we use the player's complete event to set the source to a new video. If the player's autoPlay parameter is set to true, the new video will start playing as soon as it's buffered.
That's all there is to it. If you have any further questions, let us know on the forum. Enjoy!
Other Tutorials
