flash - Does ActionScript 3 require an error event handler for XML? -


In a flash game I am developing, there are some settings set by an external XML file when I use Flash IDE I run the SWF file, so it's okay. If I run the same file as a projector (.exe) or an independent SWF file, then it does not load the XML file.

Fix my (unexpected) error event listener of the loader object when I republish the file again, the XML loaded properly in the projector and standalone SWF files. (I have since verified that the bug is restored by commenting on the event handler).

  Public function getSettings (): Zero {Output box   = GetChildByName ("Output_box") as TextField; Var xmlLoader: URLLoader = New URL Loader (); Var xmlData: XML = New XML (); XmlLoader.addEventListener (event.complete, load xml, false, 0, true); XmlLoader.addEventListener (ErrorEvent.ERROR, function (e: error) {outputbox.appendText (e.message)}); Try {XmlLoader.load (xmlPath); } Hold (error: error) {trace (err.message); OutputBox.appendText (err.message); CheckChances ("0"); } Function loadXML (e: event): zero {try {xmlData = new XML (e.target.data); Var spot: string = xmlData.chances.text (); Var dbURL: string = xmlData.database.text (); Trace ("possibilities are:" + probability); Trace ("The database is set to URL:" + dbURL); Outputbox.appendText ("The possibilities are as follows:" + Possibility); } Hold (error: error) {outputbox.appendText (err.message); } Check chains (chances); DbPath = New URLRequest (dbURL); }  

}

Let me know if you have worked on it, or if you can have some light on something you can do. Thanks!

Edit:

Here is the code that does not work (I also edit the code that will take all the other bits I picked up Displays, if they are making it effective):

  public function getSettings (): zero {outputBox = GetChildByName ("Output_box") as TextField; Var xmlLoader: URLLoader = New URL Loader (); Var xmlData: XML = New XML (); XmlLoader.addEventListener (event.complete, load xml, false, 0, true); /*xmlLoader.addEventListener (AARRARTARR, function (E: error) {outputbox.appendText (e.message)}); * / Try {xmlLoader.load (xmlPath); } Hold (error: error) {trace (err.message); OutputBox.appendText (err.message); CheckChances ("0"); } Function loadXML (e: event): zero {try {xmlData = new XML (e.target.data); Var spot: string = xmlData.chances.text (); Var dbURL: string = xmlData.database.text (); Trace ("possibilities are:" + probability); Trace ("The database is set to URL:" + dbURL); Outputbox.appendText ("The possibilities are as follows:" + Possibility); } Hold (error: error) {outputbox.appendText (err.message); } Check chains (chances); DbPath = New URLRequest (dbURL); }  

}

The first addEventListener is telling you this To use weak references (the last logic to call) Your loadXML function is defined in your getSettings () method. Once you leave GetSettings () the scope goes out of the load XML scope. The only thing that refers to loading XML is the event listener, but when you ask it to use a weak reference, which does not prevent it from garbage collection, so, when the event is picked up, the loaded Max ML method may probably collect garbage .

My guess is that when you define the unknown method by defining the other listener, then there is a getSettings () scope around the scope of that method), which will contain XML in the load.

What you really should do is to reformat your loadXML method into a real member function on your object, not a gate method defined in getSettings (). This will keep things cleaner, and the garbage collection will stop what you are seeing, because the method remains in obligation as much as the object.

If for some reason you do not want to load a member function then the weak reference flag should be sufficient to remove it to fix it. However, due to working in those anonymously the way you can end up with a little memory leak.


Comments