随机化AS3的xml flv播放列表

时间:2013-04-27 01:17:43

标签: xml actionscript-3 flv playlist

我正在尝试创建一个从AS3中的XML播放列表调用随机视频的功能,并且不知道从哪里开始。我已经尝试了多种方法,并且正在打破我的大脑。请停下来!

虽然我有一些运气拉动视频,随机化不起作用,我还需要从xml中获取标题。

<?xml version="1.0" encoding="UTF-8"?>  
<playlist>
        <video url="video/flvs/04-02-02-09-01.flv" title="angry" />    
        <video url="video/flvs/14-02-01-08-01.flv" title="happy"  />    
        <video url="video/flvs/04-02-01-04-01.flv" title="sad"  />
        <video url="video/flvs/06-02-02-03-01.flv" title="frustrated"  />
        <video url="video/flvs/21-02-02-08-01.flv" title="no emotion"  />
</playlist>

AS3:

function Init():void{
    _urlRequest = new URLRequest("playlist.xml");
    _xmlLoader = new URLLoader();
    _xmlLoader = new URLLoader(_urlRequest);
    _xmlLoader.addEventListener(Event.COMPLETE, XMLLoaded, false, 0, true);
}

function XMLLoaded($e:Event):void {
    _xml = new XML($e.target.data);
    var randomVideo:XML = _xml.video[Math.floor(_xml.video.length() * Math.random())];
    PlayVideo();
}

1 个答案:

答案 0 :(得分:1)

您可以像这样访问随机播放列表节点(假设您的XML由名为“xml”的变量引用):

var randomVideo:XML = xml.video[Math.floor(xml.video.length() * Math.random())];

您可以访问以下属性:

var randomURL:String = randomVideo.@url;
var randomTitle:String = randomVideo.@title;