After the last problem, I am very grateful to the netizen for giving me the original file "emergency". Here I am very grateful to him for his passion for Flash technology.
Some of the problems have been solved today. I have changed some of his classes. In the future, we can try to call the external loading XML method to find out our answer. I have a new view on listening for class write events. In as3.0
Read this sentence:
This. dispatchevent (new event (event. Complete ));
Getmyxml. As File
Package {
Import flash. display. Sprite;
Import flash.net. urlloader;
Import flash.net. URLRequest;
Import flash.net. urlloader;
Import flash. Events .*;
Import flash. Text. textfield;
Public class getmyxml extends sprite {
Public var myxml: XML;
Public var picarray: array = new array ();
Public var URL: string;
Public Function getmyxml (myurl: string ){
Myxml = New XML ();
Url = myurl;
VaR myurlrequest: URLRequest = new URLRequest (URL );
VaR myloader: urlloader = new urlloader (myurlrequest );
Myloader. addeventlistener (event. Complete, OK );
}
Function OK (E: Event): void {
Myxmlbeanxml(e.tar get. data );
VaR N: Int = myxml. Elements ("*"). Length ();
VaR STR: string;
For (var I: Int = 0; I <n; I ++ ){
STR = (myxml. Elements ("*") [I]). tostring ();
Picarray. Push (STR );
// Trace (picarray [I]);
}
// Trace (Me. mypic (picarray ));
// Addchild (me );
// Addchild (_ Str );
This. dispatchevent (new event (event. Complete); // This place is of special interest today. Add a listening event to the class you write.
}
}
}
Note: Reference official documents
Schedule events to the event stream. The event target is to call it.dispatchEvent()
The eventdispatcher object of the method.
Schedule events to the event stream.
Readmyxml.
Package {
Import flash. display. Sprite;
Import flash. Events .*;
Import flash. Text. textfield;
Public class readmyxml extends sprite {
Public var myarray: array = new array ();
Public Function readmyxml (){
}
Public Function mypicture (list: array): Array {
Myarray = List;
Return myarray;
}
}
}
Write at the first frame:
VaR okxml: getmyxml = new getmyxml ("pic. xml ");
Addchild (okxml );
Okxml. addeventlistener (event. Complete, good );
Function good (E: Event): void {
Trace ("good ");
VaR _ STR: textfield = new textfield ();
VaR me: readmyxml = new readmyxml ();
_ Str. Text = me. mypicture (okxml. picarray). tostring ();
Addchild (_ Str );
Addchild (me );
}
PIC. xml file
<? XML version = "1.0" encoding = "UTF-8"?>
<Map>
<JPG> a0.jpg </jpg>
<JPG> a1.jpg </jpg>
<JPG> a2.jpg </jpg>
<JPG> a3.jpg </jpg>
<JPG> a4.jpg </jpg>
<JPG> a5.jpg </jpg>
<JPG> a6.jpg </jpg>
</Map>
Before that, I often tried to add getmyxml to the document class and found that there was always an error.
It seems that there are some problems, but it will not happen if you put the source file and the as file in the same directory, and you can also call your own method.
Okay. Record some good articles next time.