Flash AS3 ( actionscript 3): XML video player, plays FLV files from XML

This is a Flash AS3 (ActionScript 3 ) example that combines a couple things that I’ve posted in the past, including the for loop and xml loading. So we use those methods in this FLV Video playlist sample. Since the xml file is in RSS 2.0 type format, you could also use this for your video feed.

What happens is: we have two AS3 components on our stage; the FLVPlayBack , and the list component. We load the xml file that holds the file data into the list component and the user can click on one of the FLV flies and the FLVPlayBack with play that video. Also, once a video reaches the end of playback, it will automatically play the next video in the list. It continues to loop through all of the FLVs in the list.

Here is the code:

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onLoaded);

myList.addEventListener(Event.CHANGE, itemChange);

function itemChange(e:Event):void {
//myPlayer.load(myList.selectedItem.data);
myPlayer.play(“http://www.smithmediafusion.com/FLV/”+myList.selectedItem.data);
}

var xml:XML;

function onLoaded(e:Event):void {

xml = new XML(e.target.data);
var il:XMLList = xml.channel.item;
for (var i:uint=0; i<il.length(); i++) {
myList.addItem({label:il.description.text()[i],
data:il.title.text()[i]});
}
}

loader.load(new URLRequest(“http://www.smithmediafusion.com/FLV/VideoPlayerData.xml?id=22222″));
myPlayer.addEventListener(Event.COMPLETE, nextFLV);
function nextFLV(e:Event):void {

var ds = myList.selectedIndex;
var dsl = myList.length;
if (myList.selectedIndex == 0) {
trace(“if = yes: “+dsl);
myList.selectedIndex = (+1);
myPlayer.play(“http://www.smithmediafusion.com/FLV/”+myList.selectedItem.data);
} else {
if ((ds+1) == dsl) {
myList.selectedIndex = 0;
myPlayer.play(“http://www.smithmediafusion.com/FLV/”+myList.selectedItem.data);
} else {
trace(“if = else”);
myList.selectedIndex = (ds+1);
myPlayer.play(“http://www.smithmediafusion.com/FLV/”+myList.selectedItem.data);
}
}
}

Here are the files:
VideoPlayer.fla
VideoPlayer.swf
VideoPlayerData.xml

FLVPlayback skin not showing up?
Make sure you have uploaded your skin swf file. Flash will put it in the same folder locally on your machine. Just upload it to the same folder where your file resides on the server.

4 Responses to “Flash AS3 ( actionscript 3): XML video player, plays FLV files from XML”

  1. D-mode Blog » Flash Helps: AS3 (actionScript 3) Podcast Player Says:

    [...] Here’s a little something called a AS3 Flash actionScript 3 Podcast player. This little sample uses similar Flash AS3 methods in past posts like the for loop, xml loading, and the Flash AS3 Video Player. [...]

  2. jesseharding.com » Salt Lake Adobe User Group Says:

    [...] My presentation is based of a tutorial by Dan Smith. [...]

  3. D-mode Blog » Salt Lake Adobe User Group Says:

    [...] The presentation is based on a tutorial by me. [...]

  4. D-mode Blog » Flash Helps: Flash CS3 List Component in AS3 (actionScript 3 ) Says:

    [...] are sorted by an index starting at 0, we can reference these elements by their index. In the Flash Video Player sample, I used a list [...]