Working with Events: Random Video Play
Updated: Apr 22, 2008
Views: 852
Description: This guide will go through the steps of creating a randomly selected video.
Complete code:
myGallery.autoPlay = true;
function eventHandler(event:Object){
myGallery.addEventListener("complete", completeVid);
}
myGallery.addEventListener("ready", eventHandler);
function completeVid(event:Object){
event.target.loadMovie(random(event.target._content.getLength()));
}
function eventHandler(event:Object){
myGallery.addEventListener("complete", completeVid);
}
myGallery.addEventListener("ready", eventHandler);
function completeVid(event:Object){
event.target.loadMovie(random(event.target._content.getLength()));
}
Loading XML file
Please see the XML tutorial on how to set up the xml file needed to load the FLV List Gallery.
Adding complete event
We will need to add a ready event. This will let us know when the player is ready to receive commands.Now inside of the function we will add a complete event listener
function eventHandler(event:Object){
myGallery.addEventListener("complete", completeVid);
}
myGallery.addEventListener("ready", eventHandler);
myGallery.addEventListener("complete", completeVid);
}
myGallery.addEventListener("ready", eventHandler);
Setting up the random selection
Once we have created a function for the complete event. This is where we will put the method that will randomly select a video from the list when ever a video is done playing.
function completeVid(event:Object){
event.target.loadMovie(random(event.target._content.getLength()));
}
event.target.loadMovie(random(event.target._content.getLength()));
}
