动态地改变闪存AS3中引用的XML文件?闪存、文件、动态、XML

2023-09-09 21:51:58 作者:姐就是有狂的资本

基本上我有被解析并使用AS3 XML文档的参考播放的媒体。这些媒体文件会被分隔成单独的XML文件,那么我正打算是其中的XML文件被引用的只是动态变化。问题是,在code只能触发一次在第2帧,我似乎无法弄清楚如何切换出XML文件,一个不同在一个事件触发。 新的URLRequest(www.blah.com/theotherXMLfile.xml)不工作...我需要重新加载的code完全是另外一个字符串转换到一个不同的XML文档?

Basically I have media being parsed and played by reference of an XML document using AS3. These media files are gonna be seperated into seperate XML files then what I was planning was to just dynamically change which XML file is being referenced. Problem is, the code only fires once on frame 2 and I can't seem to figure out how to switch out the XML file for a different one upon an event trigger. "new URLRequest(www.blah.com/theotherXMLfile.xml)" isn't working...do I need to reload a whole other string of code to change to a different XML document?

我会后在code,如果你需要它...

I'll post the code if you need it...

推荐答案

不知道这是什么你问,但更新XML,你需要的URLLoader重新加载该文件,然后重新分析XML文档。

Not sure if this is what you were asking, but to update the XML, you'll need the URLLoader to reload the file and then reparse the XML document.

下面是一个关于如何重用的URLRequest一个简单的例子。我希望我没有把任何语法错误在里面,有一个较长的AS休息..:P

Here is a quick example on how to reuse the URLRequest. I hope I didn't put any syntax errors in it, had a longer AS break.. :P

private var dataUrl:URLRequest;
private var xmlLoader:XMLLoader;
private var xmlDoc:XML;

private function init ():void
{
    dataUrl = new URLRequest( ... );

    xmlLoader = new XMLLoader( dataUrl );
    xmlLoader.addEventListener( Event.COMPLETE, parseXML );
}

public function reloadXML ()
{
    xmlLoader.load( dataUrl );
}

private function parseXML ( event:Event )
{
    xmlDoc = new XML( xmlLoader.text );

    // do something else, for example update UI etc.
}