XMLLoaderNE

/*
* XMLLoaderNE
*
* @author: showjean in http://showjean.com/works
* @version: 1.0.0
* @date: 2008.11.25.
*
* @comment: event - 
*/
import mx.events.EventDispatcher;
import com.showjean.utils.Adapter;
import com.showjean.Event;
class com.showjean.net.XMLLoaderNE extends EventDispatcher {
	private var _interval:Number;
	private var _xml:XML;
	//
	public function XMLLoaderNE() {
	}
	//로드 진행을 알리는 메소드. 
	private function checkProgress():Void {
		var l:Number = _xml.getBytesLoaded();
		if (l>0) {
			dispatchEvent({type:Event.PROGRESS, bytesLoaded:l, bytesTotal:_xml.getBytesTotal()});
		}
	}
	private function callProgressor():Void {
		clearInterval(_interval);
		_interval = _global.setInterval(this, "checkProgress", 30);
	}
	public function load(tar:String):Void {
		_xml = new XML();
		_xml.ignoreWhite = true;
		_xml.load(tar);
		callProgressor();
		_xml.onLoad = Adapter.wrap(this, __xmlLoaded, tar);
	}
	private function __xmlLoaded(suc:Boolean, tar:String):Void {
		clearInterval(_interval);
		if (suc) {
			//trace("XML loaded");
			checkProgress();
			dispatchEvent({type:Event.COMPLETE, data:_xml, url:tar});
		} else {
			//trace("XML load failed");
			dispatchEvent({type:Event.ERROR, data:_xml, url:tar});
		}
	}
}



- 사용법

System.useCodepage = true;
import com.showjean.net.XMLLoaderNE;
import com.showjean.Event;
import com.showjean.utils.Adapter;
import com.showjean.XMLNE;


var lv = new XMLLoaderNE();
lv.load("test.xml");
lv.addEventListener(Event.COMPLETE,this);
lv.addEventListener(Event.PROGRESS,this);
var obj:Object;
function complete(evt:Object):Void {
	trace(evt.data);
	obj = XMLNE.create(evt.target.firstChild);
	trace(obj.attributes.text);// -> "abcd"
	trace(obj.test[0].attributes.name);// -> "dododo"
	trace(obj.test[0].unit[0].value);// -> "showjean"
	trace(obj.test[0].unit[0].attributes.type);// -> "string"
}
function progress(evt:Object):Void {
	//trace(evt.target.getBytesLoaded());
}


'Flash > AS2.0' 카테고리의 다른 글

Event  (0) 2012.06.05
XMLNE  (0) 2012.06.05
Adapter  (0) 2012.06.05
SimpleButtonHandler //2007/03/18 13:22  (0) 2012.06.05
한글 워드랩 메쏘드 //2007/03/10 17:49  (0) 2012.06.05