/*
讀XML的PACKAGE
比一般別人寫的多了一個callback的功能
bg.9sweb.com / by egg
*/
package
{
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
public class EC_getXmlData
{
public var url :String = new String();
public var method :String = new String('GET');
public var callback_onload:Function = new Function();
public var callback_error :Function = new Function();
public var callback :Function = new Function();
private var loader :URLLoader = new URLLoader();
private var request :URLRequest = new URLRequest();
public function getdata(url = '')
{
if(url != '') this.url = url;
request.url = this.url;
request.contentType = "text/xml";
request.method = URLRequestMethod.GET;
loader.addEventListener(Event.COMPLETE,this.getComplete);
loader.addEventListener(ProgressEvent.PROGRESS,this.getProgress);
try
{
trace("loading...");
loader.load(request);
}
catch(error:Error)
{
trace(error);
callback_error(error);
}
}
private function getProgress(event:Event)
{
//trace(event.type + ", " + event.bytesLoaded + "/" + event.bytesTotal);
this.callback_onload(event);
}
private function getComplete(event:Event)
{
var myXmlData:XML = new XML(event.target.data);
this.callback(myXmlData);
}
}
}
20090123
Read Xml
TAG
ActionScript3,
Code
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言