Getxml.
Package com.org {
Import flash. display. Sprite;
Import flash.net. urlloader;
Import flash.net. URLRequest;
Import flash.net. urlloader;
Import flash. Events. event;
Import flash. Text. textfield;
Public class getxml extends sprite {
Private var myxml: xml = New XML ();
Public var picarray: array = new array ();
Public Function getxml (){
VaR URL: String = "pic. xml ";
VaR myurlrequest: URLRequest = new URLRequest (URL); // obtain the external host
VaR myloader: urlloader = new urlloader (myurlrequest); // external loading XML
Myloader. addeventlistener (event. Complete, OK); // listener Function
}
Function OK (E: Event): void {
Myxmlbeanxml(e.tar get. data );
VaR N: Int = myxml. Elements ("*"). Length (); // The total number of elements that can be output using the length () method with the asterisk parameter. For example, numelement = addressbook. Elements ("*"). Length ().
VaR STR: string;
For (var I: Int = 0; I <n; I ++ ){
STR = (myxml. Elements ("*") [I]). tostring ();
Picarray. Push (STR );
Trace (picarray [I]);
}
}
}
}
Some strange problems occurred one afternoon. The Compiler always said that I didn't define a method.
When I try to add a method, the problem occurs during the preparation of the call in the first frame.
Add code
VaR VV: getxml = new getxml ();
1180: call to a possibly undefined method addframescript is displayed.
Method Not Defined
When I try to define a method, the compiler always says that I didn't compile
Public Function Hello (): String {
VaR hh: String = "sssssss ";
Return HH;
}
Define ANOTHER METHOD
Package com.org {
Import flash. display. Sprite;
Import flash.net. urlloader;
Import flash.net. URLRequest;
Import flash.net. urlloader;
Import flash. Events. event;
Import flash. Text. textfield;
Public class getxml extends sprite {
Private var myxml: xml = New XML ();
Public var picarray: array = new array ();
Public Function getxml (){
VaR URL: String = "pic. xml ";
VaR myurlrequest: URLRequest = new URLRequest (URL); // obtain the external host
VaR myloader: urlloader = new urlloader (myurlrequest); // external loading XML
Myloader. addeventlistener (event. Complete, OK); // listener Function
}
Function OK (E: Event): void {
Myxmlbeanxml(e.tar get. data );
VaR N: Int = myxml. Elements ("*"). Length (); // The total number of elements that can be output using the length () method with the asterisk parameter. For example, numelement = addressbook. Elements ("*"). Length ().
VaR STR: string;
For (var I: Int = 0; I <n; I ++ ){
STR = (myxml. Elements ("*") [I]). tostring ();
Picarray. Push (STR );
Trace (picarray [I]);
}
}
Public Function Hello (): String {
VaR hh: String = "sssssss ";
Return HH;
}
}
}
Write at the first frame
VaR VV: getxml = new getxml ();
// Addchild (vv );
Mytext. Text = VV ["hello"] ();
Problem: same error
However
Package {
Import flash. display. Sprite;
Import flash.net. urlloader;
Import flash.net. URLRequest;
Public class myclass extends sprite {
Public var SS: string;
Public var hh: int;
Public Function myclass (){
HH = 2;
}
Public Function Hello (): String {
Ss = "sssss ";
Return SS;
}
}
}
This case has been tested and OK.
VaR YY: myclass = new myclass ();
Mytext. Text = yy. Hello ();
I really don't understand what went wrong with as3.0. I just want to write a method call. Why is it so difficult...