If you want to use a class to load XML or images and want it to return an XML or bitmap, you cannot directly return it in the class constructor because it may return
If the load is not complete, an empty value is often returned. You can try to use the callback function or use dispatchevent. If it is a small program, try the callback function again.
The Code is as follows:
Public class loadxml
{
Private var fback: function;
Public Function loadxml (URL: String, fbackin: function)
{
Fback = fbackin;
VaR xmlloader: urlloader = new urlloader ();
Xmlloader. Load (New URLRequest (URL ));
Xmlloader. addeventlistener (event. Complete, loadcomplete );
}
Private function loadcomplete (E: Event): void
{
Trace ("XML loaded OK ");
VaR xmldata: xml = new xml(e.tar get. data );
Fback (xmldata );
}
}
The main function can be written in this way, and an XML will be returned.