Packagecom.yworks.support
Classpublic class Config
InheritanceConfig Inheritance flash.events.EventDispatcher

Configuration mechanism that allows to change the application configuration of a compiled yFiles FLEX application using arbitrary configuration parameters.

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

com.yworks.mxml.ConfigTool


Public Properties
 PropertyDefined 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
Public Methods
 MethodDefined By
  
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
Events
 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
Property Detail
configURLproperty
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.


Implementation
    public function get configURL():String
    public function set configURL(value:String):void
initializedproperty 
initialized:Boolean  [read-only]

Is true when the configuration file has been parsed.


Implementation
    public function get initialized():Boolean
ioErrorHandlerproperty 
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.


Implementation
    public function set ioErrorHandler(value:Function):void
securityErrorHandlerproperty 
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.


Implementation
    public function set securityErrorHandler(value:Function):void
throwOnErrorproperty 
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;.


Implementation
    public function get throwOnError():Boolean
    public function set throwOnError(value:Boolean):void
Constructor Detail
Config()Constructor
public function Config()

This class is a singleton - use getInstance instead.


Throws
IllegalOperationError
Method Detail
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

Returns
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

Returns
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

Returns
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

Returns
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

Returns
uint — The uint value of the configuration parameter key.
Event Detail
complete Event
Event Object Type: flash.events.Event
Event.type property = flash.events.Event.COMPLETE

Dispatched when the configuration file has been parsed.

ioError Event  
Event Object Type: flash.events.IOErrorEvent
IOErrorEvent.type property = flash.events.IOErrorEvent.IO_ERROR

Dispatched when the configuration file could not be loaded.

securityError Event  
Event Object Type: flash.events.SecurityErrorEvent
SecurityErrorEvent.type property = flash.events.SecurityErrorEvent.SECURITY_ERROR

Dispatched when the configuration file could not be loaded due to a security error.