How I can get Flashvars value from a package as class, not from the timeline?
I need to assign dynamically a path to a xml file through Flashvars. How I can make it work?
I was able to get Flashvar from html page into swf with actionscript code on timeline:
1. HTML – assigning Flashvars with swfObject:
Code:
<script type="text/javascript">
var flashvars = {};
flashvars.xmlfile = "xml/data.xml";
var params = {};
var attributes = {};
attributes.id = "IdScroller";
swfobject.embedSWF("scroller.swf", "flashDiv", "975px", "600px", "9,0,0,0", "expressInstall.swf", flashvars, params, attributes);
</script>
2. Actionscript code on timeline:
Actionscript Code:
var XMLpath:String;
//get flashvar value if(root.loaderInfo.parameters["xmlfile"]!= null){ XMLpath = root.loaderInfo.parameters["xmlfile"]; }
var loader:URLLoader=new URLLoader(); loader.addEventListener(Event.COMPLETE,completeHandler);
// assign that value to URLRequest var request:URLRequest = new URLRequest(XMLpath); try { loader.load(request); } catch(error:Error) { trace('Error on loading the image.'); }
It works great, but I really need to make it work within a package class. I have trouble to make it.
I am using EventDispatcher to load XML where I define the location path with this method. Below is the code fom this class:
I also wanted to know how I can pass flashvars to a child swf. I am loading an external swf into main swf. The loaded swf has to be able to read flashvars. Any ideas???
Thanks.
you have to create a custom event dispacther which can take an array as a parameter......i use an external class witch extends event dispatcher and handles assiging the variable to the dispatch.....i can send you one if you like.
It will be great. I am using this technique forst time and have lots of milestones. Thank you again.
By the chance, I am wondering if you know how I can pass flashvars to a child swf. I am loading an external swf into main swf. The loaded swf has to be able to read flashvars. Any ideas???
Thanks.
Thank you for sending me as code. I am highly appreciate it.
I did install it in the class' directory. I have confiManager class which defines path to xml at this moment. This class public class ConfigManager extends EventDispatcher. Your class is in the same directory now. Please tell me what next I have to do and test it. Thanks.
put some traces inside the file i sent and dispatch the event to make sure it works.......you do know how to specify the package location from within the file i sent you right?
// Read the setting values from the configuration file readConfig(configXMLLoader.getXML()); dispatchEvent(new CustomEvent0("CustomEvent",false,false,"data0_tosend","data1_tosend")); dispatchEvent(new Event(ConfigManager.CONFIG_LOADED));
}
Unfortunatelly, I am getting error, no trace statements. Did I do something wrong? I also cannot seen how it will read flashvars I am getting on the timeline. Thanks again.
we need to clarify this are you wanting to get the flashVars and then use them in the xml loader or do you want to get the variables and dispatch them to another class?
I need to pass XML path via FlashVars to the class below.
I need to assign Flashvars string which I can get in the timeline to "DATA_XML_URL" I have in this class.
if(_configManager == null){ _configManager = new ConfigManager(new SingletonEnforcer()); }
return _configManager;
} }
}
this is where I define static path to the data.xml. I need to modify it in a way I can pass it with FlashVars. Basically, I need to path a string of the actual data.xml file location.
var:Classname = new Classname(root.loaderInfo.parameters["xmlfile"]);
I am getting error:
1084: Syntax error: expecting identifier before colon.
I am not sure what else I need to do. I need to assign Flashvars string which I can get in the timeline to "DATA_XML_URL" I have in this 'public class ConfigManager extends EventDispatcher'. I included this code above. Please let me know how it is possible to achieve. Thanks.
thats just an example it doesn't do anything do you know how to call a class from your document root? do you have a document root attached to your fla?
Not, I have other classes. This paricular 'public class ConfigManager extends EventDispatcher' has a reference to the statc path to data.xml which I need to modify to dynamic.