I'm trying to create a function that calls random videos from an XML playlist in AS3 and have no idea to randomization. Please help!
XML:
AS3:<?xml version="1.0" encoding="UTF-8"?>
<playlist id="Videoplayer" >
<vid desc="ClipTube1"
src="VideoClipTube1.flv" />
<vid desc="ClipTube2"
src="VideoClipTube2.flv" />
<vid desc="ClipTube3"
src="VideoClipTube3.flv" />
</playlist>
Code:public function VideoPlaylistSeq():void { // Load the playlist file, then initialize the media player. xmlLoader = new URLLoader(); xmlLoader.addEventListener(Event.COMPLETE, initMediaPlayer); xmlLoader.load(new URLRequest("Playlist.xml")); // Format the tileList, specify its cellRenderer class.; tileList.setSize(100, 350); tileList.columnWidth = 80; tileList.rowHeight = 60; tileList.direction = ScrollBarDirection.VERTICAL; tileList.setStyle("cellRenderer", Thumb); } public function initMediaPlayer(event:Event):void { var myXML:XML = new XML(xmlLoader.data); //my randomization code?? var item:XML = xmlLoader.data[Math.floor(xmlLoader.data.length() * Math.random())]; for each (item in myXML.vid) {// populate playlist. // Get thumbnail value and assign to cellrenderer. var thumb:String; if (item.hasOwnProperty("@thumb") > 0) { thumb = item. @ thumb; }// Send data to tileList. tileList.addItem({label:item.attribute("desc").toXMLString(), data:item.attribute("src").toXMLString(), source:thumb}); } // Select the first video. tileList.selectedIndex = 0; // Listen for item selection. tileList.addEventListener(Event.CHANGE, listListener); // And automatically load it into myVid.; myVid.source = tileList.selectedItem.data; // Pause video until selected or played. //myVid.pause(); // Listen for end of current video, then play the next myVid.addEventListener(VideoEvent.COMPLETE, vidComplete); } // Detect when new video is selected, and play it function listListener(event:Event):void { myVid.play(event.target.selectedItem.data); } // listen for complete event; play next video function vidComplete(eventObject:VideoEvent):void { if (tileList.selectedIndex < tileList.length - 1) { tileList.selectedIndex = tileList.selectedIndex + 1; tileList.scrollToIndex(tileList.selectedIndex); myVid.play(tileList.selectedItem.data); }




Reply With Quote