[FONT=Calibri][SIZE=3]I am trying to pass FlashVars into public class EventDispatcher to set the path to data.xml. I need it because the name and path of the xml file will be dynamically created. I need to use Flashvar in order to access the correct path.[/SIZE][/FONT]
[FONT=Calibri]I was able to pass Flashvar from html page on timeline this way:[/FONT]
var Flashvars:String = LoaderInfo(stage.loaderInfo).parameters.xmlfile;
[FONT=Calibri]Then, I was able to use it for new UrlRequest;[/FONT]
[FONT=Calibri]
var request:URLRequest = new URLRequest(Flashvars);
[/FONT]
[FONT=Calibri]This method works really good, but this solution only works on timeline.
I need to implement this technique in the class. Before I setup a static var for with the path to xml file. I’d like to be able to get FlashVar withing this class and assign this string to ‘public static var DATA_XML_URL:String’ I have there. This way I can pass Flashwar to the project I already have.
I am wondering if it is doable from what I described. I already spent a gay for it but obviously stack here. Any help is highly appreciate.
Below is the class where I can implement it:
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.display.Sprite;
import flash.display.LoaderInfo;
import flash.display.MovieClip;
import flash.display.Stage;
public class ConfigManager extends EventDispatcher {
//private var loaderInfo:LoaderInfo;
private var _targetLoaderInfo:LoaderInfo;
// The name of the event to be fired when configuration is read
public static const CONFIG_LOADED:String = "configLoaded";
// Location of the data xml file
public static var DATA_XML_URL:String = "xml/data.xml";
public static var PHOTO_DIR:String = "images/profile/"
private var configXMLLoader:XMLLoader;
// Xml data
private var xml:XML;
// A reference to the ConfigManager
private static var _configManager:ConfigManager;
private var test1:String = "";
public function ConfigManager(singletonEnforcer:SingletonEnforcer) {
// NOTHING HERE
}
public function load():void {
// Create a new XMLLoader object
//DATA_XML_URL = LoaderInfo(stage.loaderInfo).parameters.xmlfile;
//Or it can be this way
/*if (LoaderInfo(this.parent.parent.loaderInfo).parameters.xmlfile !== undefined){
test1 = LoaderInfo(this.parent.parent.loaderInfo).parameters.xmlfile;
DATA_XML_URL = test1;
}*/
init();
}
public function init():void {
configXMLLoader = new XMLLoader(CONFIG_XML_URL);
// Add an event listener to be dispatched when xml is parsed.
configXMLLoader.addEventListener(XMLLoader.XML_LOADED, onConfigXMLLoaded);
// Start loading the file
configXMLLoader.load();
}
private function readConfig(xml:XML):void {
// Read configurations here
PHOTO_DIR = xml.@photoDir;
}
//This method is called when the configuration file is loaded.
private function onConfigXMLLoaded(evt:Event):void {
// Read the setting values from the configuration file
readConfig(configXMLLoader.getXML());
dispatchEvent(new Event(ConfigManager.CONFIG_LOADED));
}
// Returns the configuration manager.
public static function getInstance():ConfigManager {
if (_configManager == null) {
_configManager = new ConfigManager(new SingletonEnforcer());
}
return _configManager;
}
}
}
[/FONT][FONT=Calibri][/FONT]