XMLLoader, a custom class.

I devised the XMLLoader class to avoid the URLLoader bug that I posted on FlaLab.com.
Related links
예전에 FlaLab에 올렸던 URLLoader의 버그를 회피하기 위해서 만든 XMLLoader 클래스 입니다.
참고 링크
私がFlaLab.comに書いたURLLoaderのバーグを回避するためにXMLLoaderクラスを作りました。
参考リンク

http://www.flalab.com/phpBB2/viewtopic.php?t=1791
http://www.flalab.com/phpBB2/viewtopic.php?t=2228

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/**
 * XMLLoader
 *
 * XMLLoader class loads and validates an XML file.
 * If you loads a text file encoded in the euc-kr encoding via an URLLoader, frequently, the source data is currupted.
 * To avoid this problem, parses the loaded data into an XMLDocument,
 * then, parses the first node of the XMLDocument into an XML.
 * If an error has been occured, reloads the XML data.
 * 
 *
 * @author: Han Sanghun (http://hangunsworld.com, hanguns@gmail.com)
 * @created: 2008 02 28
 * @last modified: 2008 02 29
 */
 
 
package com.hangunsworld.as3.net{
 
	import	flash.events.*;
	import	flash.net.*;
	import	flash.utils.Timer;
	import	flash.xml.*;
 
 
	public class XMLLoader{
 
 
		private var path:String;
		private var returnFunction:Function;
		private var errorFunction:Function;
 
		private var timer:Timer;
		private var xml:XML;
 
		private var xml_ul:URLLoader;
		private var xml_ur:URLRequest;
		private var xml_uv:URLVariables;
 
		/**
		 * XMLLoader constructor
		 *
		 * @param pPath A path of an XML file
		 * @param okFunc A function to call when the XML is loaded successfully
		 * @param errorFunc A function to call when an IOError has occured
		 */
		public function XMLLoader(pPath:String, okFunc:Function=null, errorFunc:Function=null){
 
			path = pPath;
			returnFunction = okFunc;
			errorFunction = errorFunc
 
			XML.ignoreWhitespace = true;
			XML.ignoreComments = true;
 
 
			// Initializes NET objects
			xml_ul = new URLLoader();
			xml_ul.addEventListener (Event.COMPLETE, xmlCompleteListener);
			xml_ul.addEventListener (IOErrorEvent.IO_ERROR, errorListener);
 
			xml_ur = new URLRequest();
			xml_ur.url = path;
 
			xml_uv = new URLVariables();
 
 
			// Initializes Timer object
			timer = new Timer(50, 1);
			timer.addEventListener(TimerEvent.TIMER, timerListener);
 
			timer.start();
 
 
		}// end constructor
 
 
		/**
		 * Timer EventListener
		 * Loads an XML file after some time
		 */
		private function timerListener(evt:TimerEvent):void{
			loadXML();
		}// end timerListener
 
 
		/**
		 * Loads an XML file
		 */
		private function loadXML():void{
 
			if(path.indexOf("?") >= 0){
				// If the url already contains parameters, attaches the random seed to the end of the url
				xml_ur.url = path + "&randomSeed=" + Math.floor(Math.random() * 1000000);
			}else{
				// If the url does not contain parameters, uses an URLVariable object
				xml_uv.randomSeed = Math.floor(Math.random() * 1000000);
				xml_ur.data = xml_uv;
			}
 
			xml_ul.load (xml_ur);
 
		}// end loadXML
 
 
		/**
		 * XML Complete EventListener
		 */
		private function xmlCompleteListener(evt:Event):void{
 
			// Sets the defualt parse state to false
			var parsed:Boolean = false;
 
			var str:String = evt.target.data;
 
			var xmldoc:XMLDocument = new XMLDocument();
			xmldoc.ignoreWhite = true;
 
			try{
 
				// Parses the loaded data into an XMLDocument
				xmldoc.parseXML(str);
 
				// Gets a string from the first node of the XMLDocument
				str = xmldoc.firstChild.toString();
 
				// Parses the string into an XML
				xml = new XML(str);
 
				// If no error has occured, sets the parse stae to true
				parsed = true;
 
			}catch(e){
 
				// If an error occured, loads the XML again
				timer.start();
 
			}// end try catch
 
 
			// If the parse process done without errors and the returnFunction is NOT null, returns the XML data
			if(parsed){
				if(returnFunction != null){
					returnFunction(xml);
				}
			}
 
 
		}// end xmlCompleteListener
 
		/**
		 * XML IOError EventListener
		 */
		private function errorListener(evt:IOErrorEvent):void{
 
			if(errorFunction != null){
				errorFunction(evt);
			}
 
		}// end xmlErrorListener
 
 
	}// end class
 
}// end package
1
2
3
4
5
6
7
8
9
10
11
12
import	com.hangunsworld.as3.net.XMLLoader;
 
var xloader:XMLLoader;
xloader = new XMLLoader(xmlPath, xmlLoaded, xmlErrorListener);
 
function xmlLoaded(xx:XML):void{
	// xml loaded
}
 
function xmlErrorListener(evt:IOErrorEvent):void{
	trace("xml load error");
}

IE ACA Preview #2 update is available.

Microsoft released Internet Explorer Automatic Component Activation (IE ACA) Preview #2 update which will disable the “Click to activate” behavior. You have to install Internet Explorer update 944533 (security bulletin MS08-010) before you install IE ACA preview #2 update.
마이크로소프트에서 인터넷 익스플로어 컴퍼넌트 자동 활성화(IE ACA) 프리뷰 2 업데이트를 공개했습니다. 이 업데이트는 더 이상 “Click to activate” 메세지를 표시하지 않도록 합니다. 이 IE ACA 프리뷰 2를 설치하기 전에, 반드시 인터넷 익스플로어 업데이느 944533 (security bulletin MS08-010)을 설치해야 합니다.
マイクロソフトがInternet Explorer Automatic Component Activation (IE ACA) Preview #2 updateをリリースしました。このアップデートは”クリックしてアクティブ化する”動作を無効にします。このアップデートを展開する前に、必ず Internet Explorer update 944533 (security bulletin MS08-010)が適用されているのか確かめて下さい。

http://support.microsoft.com/kb/947518
IE Automatic Component Activation Preview Available
Goodbye to “Click To Activate”

Array.length is a read-write property.

Array.length is a read-write property. I should’ve know it.
I just thought it was a read-only property. I came to know it reading a copy of EAS3.0.
Array.length 속성이 리드-라이트 였네요. 이런걸 지금까지 모르고 있었다니…
당연히 Read-only일 거라고 생각하고 있었는데, EAS3.0을 보다가 알게 되었네요.
Array.lengthがread-write属性だったんですね。なぜ今まで知らなかったんだろう……
当然read-onlyだと思っていったのに、EAS3.0を読みながら分かった。

length property
length:uint [read-write]

Language Version : ActionScript 3.0
Player Version : Flash Player 9

A non-negative integer specifying the number of elements in the array. This property is automatically updated when new elements are added to the array. When you assign a value to an array element (for example, my_array[index] = value), if index is a number, and index+1 is greater than the length property, the length property is updated to index+1.

Note: If you assign a value to the length property that is shorter than the existing length, the array will be truncated.

quote from ActionScript 3.0 Language Reference

1
2
3
4
var arr:Array = new Array(0, 1, 2, 3, 4, 5, 6);
trace(arr);// output 0,1,2,3,4,5,6
arr.length = 4;
trace(arr);// output 0,1,2,3
If the newly assigned length is shorter than the existing value, items whose index is larger than the length will be removed from the array and the array will be shortened to the specified length. In some cases, it is more useful than Array.slice() or Array.splice() methods.
위와 같이 length에 현재 길이보다 작은 값을 입력하면, length 이후의 아이템들을 제거하고 배열이 입력받은 길이로 줄어들게 됩니다. 경우에 따라서는 Array.slice(), Array.splice() 보다 유용할 것 같네요.
若し、新しいlengthが現在のlengthより少ないと、それ以後の配列要素は取り去れて、その配列の長さは短くなります。時折Array.slice()やArray.splice()メソッドより便利そうです。

English as a Second Language Podcast

This may be helpful for peoples who are learning English. Especially, it can improve listening skils. It is a free podcast, and you can use it through softwares or machines that support the podcast.

English as a Second Language Podcast homepage

Go to “Listen with iTunes” menu, and click “click here” link in the “Using iTunes > 2. After you installed…” line. For more infomation, check the ESL homepage.

영어 공부에 관심있는 분들에게 도움이 될 것 같습니다. 특히 리스닝에 많은 도움이 될 것 같네요.
무료 팟캐스트로 아이튠 등 팟캐스트를 지원하는 프로그램이나 기기를 통해서 들을 수 있습니다.

English as a Second Language Podcast 홈페이지

Listen with iTunes 메뉴로 들어가서 Using iTunes > 2. After you have installed… 줄의 click here 링크를 클릭하면, 아이튠이 실행됩니다. 먼저 아이튠이 설치되어 있어야 하며, 아이튠 환경설정 > 유해 컨텐츠 차단 메뉴에서 음원 > Podcast 비활성화의 체크가 해제되어 있어야 합니다.
기타 자세한 설명은 해당 페이지를 참고하세요.

英語を習いたがっている人に役に立ちそう。特にリスニングに良いと思います。
無料ポッドキャストなので、iTunesなどのポッドキャストを使えるソフトウエアや機器を通じて聞けるんです。

English as a Second Language Podcast ホームページ

Listen with iTunes メーにュに入って、Using iTunes > 2. After you have installed…行のclick hereリンクをクリックするとiTunesが起動されます。もっと詳しい説明はESL homepageを見てください。

via fladdict.net blog