What have we done so far?
Before we get started building those new methods let’s recap what was discussed in the initial article. First of all we have the config.xml file where parameters are defined. That file looked something like this:
<?xml version="1.0" ?>
<config>
<param id="companyName" value="DMXzone" />
<param id="companyLink" value="http://www.dmxzone.com" />
</config>
The id attribute of the param nodes specified the variable name in your FLA and the value attribute, as its name suggests, holds the value of that variable.
What would happen in the FLA is that the configuration XML file gets loaded in and throughout the application a getConfigParam method is used to get the hold of the appropriate value. When a variable is defined both in the FLA and the XML file, the value from the XML file would take precedence.
The getconfigParam method accepts one argument which is the variable name you want to get the value for. Here is what the code for that method looks like:
getConfigParam = function(param:String) {
var tmp = configXML["idMap"][param];
if(tmp == undefined) {
tmp = this[param];
}
return tmp;
}
In the example I used in the previous article the FLA had three variables defined: companyName, companyLink and videoFile.
var companyName:String = "My Default Company";
var companyLink:String = "http://www.visitmehere.com";
var videoFile:String = "video1.flv";
Because companyName and companyLink are defined in the XML file those two variables would be ignored when using the getConfigParam method. The videoFile variable on the other hand isn’t in the XML file and as a result the default value defined in the FLA is used.
If at any time the videoFile variable needs to be overwritten we could then simply add it to the configuration XML file and have the application working without having to recompile anything.