[AS 2.0] LoadVars 클래스의 onLoad 와 onData

ActionScript 2.0 — Tags: , , — Siaa @ 1:41 pm

LoadVars.onLoad() 메서드와 LoadVars.onData() 메서드의 차이점을 알아보자.

예를 들어, data.txt의 내용이 다음과 같을 때

&mydata=A+B-C*D/E&
var myLoader:LoadVars = new LoadVars();
myLoader.onLoad = function (success:Boolean):Void {
    if (success) {
		trace(" ----- load success ----- ");
		for(var property in this){
			trace(property + ", Type=" + typeof this[property] + ", Value=" + this[property]);
		}
    } else {
		trace(" ----- load fail ----- ");

    }
}

myLoader.load("data.txt");

// Output
// ----- load success -----
//mydata, Type=string, Value=A B-C*D/E
//onLoad, Type=function, Value=[type Function]

결과를 보면 “+” 가 빈칸으로 나온다.

var myLoader:LoadVars = new LoadVars();
myLoader.onData = function (src:String):Void {
    if (src != undefined) {
		trace(" ----- load success ----- ");
        trace(src);
    } else {
       trace(" ----- load fail ----- ");
    }
}

myLoader.load("data.txt");

// Output
// ----- load success -----
//&mydata=A+B-C*D/E&

결과를 보면 모든 데이터를 정상적으로 불러온다.

이 처럼 LoadVars.onLoad() 메서드에서만 “+”값이 빈칸으로 나오는 이유는 LoadVars.onLoad() 메서드는 읽어온 변수를 우선 파싱한 뒤, LoadVars 객체 인스턴스에 변수를 만들기 때문이다~

Share

0 Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2012 blog.flasia.com | powered by WordPress with Barecity