开发者

how to load external xml using air application for flash programmer?

i have faced this problem couple of days ago, while trying to import an external xml file into an AIR application.

 import flash.net.URLRequest;
 var ldr:Loader = new Loader();
 var url:String = "http://willperone.net/rss.php";
 var urlReq:URLRequest = new URLR开发者_StackOverflowequest(url);
 ldr.load(urlReq);
 ldr.addEventListener(Event.COMPLETE , function(e) {
    trace('Wow, completed ...');
 });
 ldr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, function(e) {
    trace('IO_ERROR');
 });

and always the IO_ERROR shows up. may i do it wrong or something needs a little of configuration, so please help


The IOErrorEvent is telling you that it can't load the resource you are trying to load. Is there anything actually at http://willperone.net/rss.php. Perhaps an XML or PHP parse error? I also just noticed you are using Loader to try to load text content. The class you want to use to load XML (or text, json, binary, etc.) is URLLoader. Loader is a DisplayObject subclass mostly for loading swfs, images, and visual assets into the display list. This is the likely culprit.


Thank you guys, i found where the problem is : i didn't specify the type of the received content, it solved when i used

request.contentType = "text/xml";

so the code will look like this :

function getData(onComplete) {
    var request:URLRequest = new URLRequest("http://...");
    request.contentType = "text/xml";
    request.data = "";
    request.method = URLRequestMethod.POST;
    var loader:URLLoader = new URLLoader();
    loader.addEventListener(Event.COMPLETE ,function(e) { xmlParser(e); onComplete(e); } );
    try
    {
        mainData.splice(0,mainData.length);
        loader.load(request);
        return true;
    }
    catch (e){
        return false;
    }
}


function xmlParser(e) {
    var xml:XML = new XML(URLLoader(e.target).data);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜