home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mobiclic 150
/
MOBICLIC150.ISO
/
pc
/
DATA
/
DSS150
/
DSS150_01
/
DSS150_01.swf
/
scripts
/
dss150_01
/
ObjectInitializer.as
< prev
Wrap
Text File
|
2012-12-19
|
4KB
|
123 lines
package dss150_01
{
public class ObjectInitializer
{
private var _instance = null;
private var _object = null;
private var _initObject = null;
public function ObjectInitializer(instance:*, object:Object, initObject:* = null)
{
super();
this._instance = instance;
this._object = object;
this._initObject = initObject;
this.initialize();
}
private function destroy() : void
{
this._instance = null;
this._object = null;
this._initObject = null;
}
private function initialize() : void
{
if(this._initObject == null)
{
this.destroy();
return;
}
if(this._initObject is XML)
{
this.fromXML(this._initObject);
this.destroy();
}
else if(this._initObject is XMLList)
{
this.fromXML(this._initObject[0]);
this.destroy();
}
else if(this._initObject is Object)
{
this.fromObject(this._initObject);
this.destroy();
}
}
private function fromObject(obj:*) : void
{
var prop:* = null;
for(prop in obj as Object)
{
this._object[prop] = obj[prop];
}
}
private function fromXML(xml:XML) : void
{
var type:String = null;
var node:XML = null;
var prop:String = null;
var list:XMLList = xml.Param;
for each(node in list)
{
if(node.hasOwnProperty("@type"))
{
type = String(node.@type);
}
else if(this._instance[node.@nom] !== undefined)
{
if(this._instance[node.@nom] is Boolean)
{
type = "boolean";
}
else if(this._instance[node.@nom] is Number)
{
type = "number";
}
else if(this._instance[node.@nom] is int)
{
type = "int";
}
else if(this._instance[node.@nom] is String)
{
type = "string";
}
else if(this._instance[node.@nom] is Array)
{
type = "array";
}
}
else
{
type = "string";
}
switch(type)
{
case "boolean":
this._object[node.@nom] = this._instance[node.@nom] = String(node.@valeur) == "true" ? true : false;
break;
case "number":
this._object[node.@nom] = this._instance[node.@nom] = Number(node.@valeur);
break;
case "int":
this._object[node.@nom] = this._instance[node.@nom] = int(node.@valeur);
break;
case "array":
this._object[node.@nom] = this._instance[node.@nom] = String(node.@valeur).split(",");
break;
case "string":
this._object[node.@nom] = this._instance[node.@nom] = String(node.@valeur);
break;
}
}
}
}
}