问题
I want to call a web page from Flash and use the data returned from it (either in plain text or XML). I see with the NetConnection you can connect to a web service, but I just want to call a plain old web page.
It seems like I managed to do this a while back, but for the life of me, I can't find the answer on the web. Does anyone know what the function / code is to call a web page in Flash and get the data back?
Thanks,
回答1:
All you need to do is use a URLLoader.
var urlRequest:URLRequest= new URLRequest("http://example.com/page/");
_urlLoader = new URLLoader();
_urlLoader.addEventListener(Event.COMPLETE, onXMLDataLoaded, false, 0, true);
_urlLoader.load(urlRequest);
function onXMLDataLoaded(evt:Event):void {
var xml = new XML(_urlLoader.data);
}
回答2:
Well, if you're using AS3 then you'll want to use the URLLoader class. One common mistake using URLLoader is that you need to pass it an instance of URLRequest like so:
var loader:URLoader = new URLLoader();
loader.load(new URLRequest("http://www.stackoverflow.com"));
Note that you use the URLRequest object to specify and GET/POST parameters you want to send so in that case you want to build the URLRequest separately rather than inline.
来源:https://stackoverflow.com/questions/1045986/flash-ajax-call