开发者

How to get output of a webpage in ActionScript 3

Let's say this page

www.example.com/mypage

returns some html that I want 开发者_开发问答to parse in Actionscript.

How do i call this page from Actionscript while getting back the response in a string variable?


Try this:

import flash.net.*

var _loader:URLLoader = new URLLoader();
var _req:URLRequest = new URLRequest('http://www.google.com');
_loader.addEventListener(Event.COMPLETE, _onComplete);
_loader.load(_req);

function _onComplete(e:Event):void{
    trace(String(_loader.data));
}


you will need to use URLLoader and load the data as plain text. here's some sample code.

var loader:URLLoader = new URLLoader(new URLRequest("www.example.com/mypage"));
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(Event.COMPLETE, parseReturn);       
function parseReturn(e:Event):void {
    var response:String = (e.target as URLLoader).data;
    //do parsing here
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜