Config.as
Object
|---LoadVars
|---Config
Requires : stringUtils.as
The Config object is an ActionScript object that loads name / value pairs from a config / ini file. This is useful for setting and loading default parameters for Flash based apps.
Usage :
#include "Config.as"
config = new Config("config.ini");
config.onConfigLoad = function(success)
{
trace("Accessing data from onConfigLoad : ClassGuid = " + this.get("ClassGuid"));
}
config.loadConfig();
The config file loaded must be in a name, value format with names and values separate by an equal sign. Lines are separated by line returns. Lines that begin with '#', ';', '[', '/' are ignored by the Config object. The Config object should be able to work with any standard config file, including windows ini, inf file. Here is an example inf file that could be loaded into Config object.
; 1394.INF -- This file contains descriptions of all the 1394
; Host controllers supported in Windows NT and Memphis
;
;*** Created 07/09/97 (Creation Date)
[Version]
;Signature="$WINDOWS NT$" ; JSG - What to do???
Signature="$CHICAGO$"
Class=1394
ClassGuid={6BDD1FC1-810F-11D0-BEC7-08002BE2092F}
Provider=%MSFT%
LayoutFile=layout.inf, layout1.inf
DriverVer=11/14/1999,5.00.2183.1
; =================== Class Sections ===========================
[ClassInstall32]
Addreg=1394ClassReg
[ClassInstall]
Addreg=1394ClassReg
Of course, you own config files may be more simple:
#config file for flash app
#this is the gateway url
gateWayURL = "http://localhost:8765/flashservices/gateway"
#this is the service name
serviceName = "myService"
You can check whether or not the Config.as file is available with the following code snippet:
if(Config.configDefined)
{
//Config.as is included
}
else
{
//Config.as could not be found
}
You can access the version number of the Config.as file like so:
var versionNumber = Config.configVersion;
trace(versionNumber)
Note that the Config object extends the LoadVars object, and thus any methods available in the LoadVars object will also be available to the Config object.
Useful methods inherited from the LoadVars object : getBytesLoaded(), getBytesTotal()
new Config(string) |
This is the constructor for the config object, which can take an optional string parameter that points to the config file to be loaded. The path to the config file can be a relative or absolute file or URL path. All Flash domain security restrictions apply. Note that the constructor is placed in the _global scope and can thus be accessed from anywhere within the Flash movie.
|
loaded |
This property is a boolean which indicates whether or not data has loaded into the config file. If loadConfig() or parse() are called, then it will be set to false, and then set to true if the config file is successfully parsed. Note, that this property can be used with Object.watch().
|
setFileName(string) |
Method that allows you to set the path to the config file. The path to the config file can be a relative or absolute file or URL path. All Flash domain security restrictions apply.
|
getFileName() |
Returns a string of the path to the current config file. If a config file has not been specified, then it returns null;
|
setStripQuotes(Boolean) |
Method which takes a Boolean value that indicates whether Default is false. For example, if you had the following config.ini file: foo = "jar jar"
Here is with setStripQuotes called with true:
And with setStripQuotes passed false (or not called) :
The difference being that when setStripQuotes is set to true, the value does not contain the quotes. Note : for performance consideration, you should only call setStripQuotes(true) if there is a possibility that your ini file with have quotes surrounding the data.
|
setExplodeValues(boolean) |
Method which takes a Boolean value that indicates whether or not values that contain commas should be exploded into an array of values. If set to true, calling get() on the name will return an Array. If set to false, calling get() on the name will return a string. The default is false. For example if you had the following config file:
And with pass true to setExplodeValues :
|
parse(string) |
This is a convenience method that allows you to pass a string representing a config file to be parsed. It returns true if the parsing succeed, and false if it did not. Note, since the method returns immediately, you may access For example:
If the config object has already parsed data, then the new data will
be added
|
get(string) |
Takes a string and returns the value for that name in the config file. For example if you had the following config file: config.ini
|
getArray() |
Returns an associative array containing the name value pairs contained within the object.
|
loadConfig() |
This method loads the config file specified in the constructor or setConfigFile() method, and then parses it. Once it has been parsed, the onConfigLoad() method will be The onConfigLoad method should be over ridden in order to
|