我正在使用URLLoader解析我的flex项目中的XML提要,问题是在Evevent.COMPLETE中匹配/检测加载的提要, 我不知道如何通过URLloader传递id或变量或对象标签。 加载图像时,这是通过在Loader中使用name属性来解决的,但是Loader不能用于XML,你能帮助我吗?
private function readXmlFeed():void {
XML.ignoreWhitespace = true;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, parseFeedXMLComplete);
xmlLoader.load(new URLRequest(url));
}
private function parseFeedXMLComplete(e:Event):void {
var feed:XML = new XML(e.target.data);
switch (e.target.name) {
case "feed1":
break;
case "feed2":
break;
}
}
答案 0 :(得分:1)
您可以扩展URLLoader:
package {
import flash.net.URLLoader;
import flash.net.URLRequest;
public class FooURLLoader extends URLLoader {
public var id : String;
public function FooURLLoader(id : String) {
super(null);
this.id = id;
}
}
}
然后:
private function readXmlFeed(id:String):void {
XML.ignoreWhitespace = true;
var xmlLoader:URLLoader = new FooURLLoader(id);
xmlLoader.addEventListener(Event.COMPLETE, parseFeedXMLComplete);
xmlLoader.load(new URLRequest(url));
}
private function parseFeedXMLComplete(e:Event):void {
var feed:XML = new XML(e.target.data);
switch (e.target.id) {
case "feed1":
break;
case "feed2";
break;
}
}