Package | com.yworks.support |
Class | public class Config |
Inheritance | Config flash.events.EventDispatcher |
Since the config file is loaded asynchronously, config parameters
cannot be read before the Event.COMPLETE
event
has been dispatched.
The configuration file will not be loaded until an event listener
for the Event.COMPLETE
event type is added.
Example usage: var cfg:Config = Config.getInstance(); cfg.configURL = "../../config.xml"; cfg.addEventListener( Event.COMPLETE, configLoaded ); function configLoaded( evt:Event ):void { var portNumber:int = cfg.getInt( "portNumber" ); }Reading the configuration can also be done using MXML with the com.yworks.mxml.ConfigTool
Configuration parameters will be parsed from a XML file using the following format:
<?xml version="1.0"?> <config> <param1>value1</param1> <param2>value2</param2> .. <paramN>valueN</paramN> </config>
See also
Property | Defined By | ||
---|---|---|---|
configURL : String
Get or set the url of the configuration XML file. | Config | ||
initialized : Boolean [read-only]
Is true when the configuration file has been parsed. | Config | ||
ioErrorHandler : Function [write-only]
Set a handler function that will be called when an
IOErrorEvent.IO_ERROR is fired when
loading the config file. | Config | ||
securityErrorHandler : Function [write-only]
Set a handler function that will be called when an
SecurityErrorEvent.SECURITY_ERROR is fired when
loading the config file. | Config | ||
throwOnError : Boolean
Get or set whether to throw errors when the
config file could not be loaded. | Config |
Method | Defined By | ||
---|---|---|---|
Config()
This class is a singleton - use getInstance instead. | Config | ||
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0.0, useWeakReference:Boolean = false):void [override]
If a listener is added for the Event.COMPLETE event type,
this implementation will trigger loading of the config file. | Config | ||
getBoolean(key:String):Boolean
Returns the value of a key as Boolean
| Config | ||
[static]
| Config | ||
getInt(key:String):int
Returns the value of a key as int
| Config | ||
getNumber(key:String):Number
Returns the value of a key as Number
| Config | ||
getProperty(key:String):String
Returns the value of a key as String
| Config | ||
getUint(key:String):uint
Returns the value of a key as uint
| Config |
Event | Summary | Defined By | ||
---|---|---|---|---|
Dispatched when the configuration file has been parsed. | Config | |||
Dispatched when the configuration file could not be loaded. | Config | |||
Dispatched when the configuration file could not be loaded due to a security error. | Config |
configURL | property |
configURL:String
Get or set the url of the configuration XML file.
This property has to be set before an event listener for
the Event.COMPLETE
event is added.
public function get configURL():String
public function set configURL(value:String):void
initialized | property |
initialized:Boolean
[read-only]
Is true
when the configuration file has been parsed.
public function get initialized():Boolean
ioErrorHandler | property |
ioErrorHandler:Function
[write-only]
Set a handler function that will be called when an
IOErrorEvent.IO_ERROR
is fired when
loading the config file.
The default value is null
.
public function set ioErrorHandler(value:Function):void
securityErrorHandler | property |
securityErrorHandler:Function
[write-only]
Set a handler function that will be called when an
SecurityErrorEvent.SECURITY_ERROR
is fired when
loading the config file.
The default value is null
.
public function set securityErrorHandler(value:Function):void
throwOnError | property |
throwOnError:Boolean
Get or set whether to throw errors when the config file could not be loaded.
Important: as the config is loaded asynchronously, it is not possible
to catch such an error. Thus, it is not recommended to set this property
to true
. It is recommended to handle errors by the
securityErrorHandler
and ioErrorHandler
.
Future versions may not support this property anymore.
The default value is false;
.
public function get throwOnError():Boolean
public function set throwOnError(value:Boolean):void
Config | () | Constructor |
public function Config()
This class is a singleton - use getInstance
instead.
IllegalOperationError
|
addEventListener | () | method |
override public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0.0, useWeakReference:Boolean = false):void
If a listener is added for the Event.COMPLETE
event type,
this implementation will trigger loading of the config file.
Parameters
type:String | |
listener:Function | |
useCapture:Boolean (default = false )
| |
priority:int (default = 0.0 )
| |
useWeakReference:Boolean (default = false )
|
getBoolean | () | method |
public function getBoolean(key:String):Boolean
Returns the value of a key as Boolean
Parameters
key:String |
Boolean — The boolean value of the configuration parameter key .
|
getInstance | () | method |
public static function getInstance():Config
Returns
Config — The shared instance of the configuration class.
|
getInt | () | method |
public function getInt(key:String):int
Returns the value of a key as int
Parameters
key:String |
int — The int value of the configuration parameter key .
|
getNumber | () | method |
public function getNumber(key:String):Number
Returns the value of a key as Number
Parameters
key:String |
Number — The Number value of the configuration parameter key .
|
getProperty | () | method |
public function getProperty(key:String):String
Returns the value of a key as String
Parameters
key:String |
String — The string value of the configuration parameter key .
|
getUint | () | method |
public function getUint(key:String):uint
Returns the value of a key as uint
Parameters
key:String |
uint — The uint value of the configuration parameter key .
|
complete | Event |
flash.events.Event
flash.events.Event.COMPLETE
Dispatched when the configuration file has been parsed.
ioError | Event |
flash.events.IOErrorEvent
flash.events.IOErrorEvent.IO_ERROR
Dispatched when the configuration file could not be loaded.
securityError | Event |
flash.events.SecurityErrorEvent
flash.events.SecurityErrorEvent.SECURITY_ERROR
Dispatched when the configuration file could not be loaded due to a security error.