Tuesday, 5 July 2011

Play videos consecutively using AS3

In this quick tip I will show you how to play videos consecutively using the FLVPlayback component in Actionscript 3.

You will need an instance of the FLVPlayback component in the library which can be found on the menu bar by selecting Windows > Components > Video and dragging the component into the library. For more information on the FLVPlayback component take a look at the documentation.

import fl.video.FLVPlayback;
import flash.events.Event;

//Arrays of videos
var videoArray:Array = new Array('vid1.flv',  'vid3.flv',  'vid3.flv');

//Array index
var index:uint = 0;

//This adds the FLVPlayback component on the stage and plays the first video
//in the array.
var video:FLVPlayback = new FLVPlayback();
video.play(videoArray[0]);
video.addEventListener(Event.COMPLETE, videoHandler);
addChild(video);

//This function plays the next video when the current video has finished playing.
function videoHandler(e:Event):void{
(index >= videoArray.length) ? index = 0 : index++;     
video.play(videoArray[index]);
}



0 comments:

  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP