Hi.
Im completely new to Flash/AS but I have some experience in other programming languages. Im trying to load some external data into my program via this code (somewhat trimmes, but the essentials are there):
vis.fla:
import visualization.*;
var settings:Settings;
settings = new Settings();
settings.loadSystemParameters();
trace("vis.fla: " + settings.getUpdateInterval());
Settings.as:
package visualization{
import flash.events.*;
import flash.net.*;
import fl.motion.Color;
import flash.errors.*;
import flash.net.URLLoader;
import flash.net.URLRequest;
public class Settings {
private var updateInterval:int;
private var settingsLoaded:Boolean;
public function Settings() {}
public function loadSystemParameters():void {
trace("System1 loadSystemParameters() start");
var systemXML:XML;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, loadingComlete);
loader.load(new URLRequest("c:\\settings.xml"));
function loadingComlete(evt:Event):void {
trace("System1 loadingComplete() start");
try {
systemXML = new XML(loader.data);
} catch (error:Error) {
trace("Error in the XML file: " + error.message + "
Cannot read the data. Shutting down.");
//Code to shut down the visualisation goes here.
return;
}
// Load the data.
this.updateInterval = systemXML.updateInterval.text();
trace("Settings: " + this.updateInterval);
trace("System1 loadingComplete( end)");
}
trace("System1 loadSystemParameters() end");
}
public function getUpdateInterval():int {
return this.updateInterval;
}
}//End System
}//End package
What happens when i execute is this:
System1 loadSystemParameters() start
System1 loadSystemParameters() end
vis.fla: 0
System1 loadingComplete() start
Settings: 600
System1 loadingComplete( end)
So the code in the vis.fla is executed to the end before all the data from settings.xml is read and I do not want that. I tried searching and reading about this, but i cannot find the solution. Is there some kind of flag you can set so that the system won´t execute the code after the loadSystemParameters() before all of the function is finished?
Thanks