home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mobiclic 148
/
MOBICLIC148.ISO
/
mac
/
DATA
/
DSS148
/
DSS148_01
/
DSS148_01.swf
/
scripts
/
dss148_01
/
ObjectInitializer.as
< prev
Wrap
Text File
|
2012-10-16
|
4KB
|
123 lines
package dss148_01
{
public class ObjectInitializer
{
private var _instance = null;
private var _object = null;
private var _initObject = null;
public function ObjectInitializer(param1:*, param2:Object, param3:* = null)
{
super();
this._instance = param1;
this._object = param2;
this._initObject = param3;
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(param1:*) : void
{
var _loc2_:* = null;
for(_loc2_ in param1 as Object)
{
this._object[_loc2_] = param1[_loc2_];
}
}
private function fromXML(param1:XML) : void
{
var _loc2_:String = null;
var _loc4_:XML = null;
var _loc5_:String = null;
var _loc3_:XMLList = param1.Param;
for each(_loc4_ in _loc3_)
{
if(_loc4_.hasOwnProperty("@type"))
{
_loc2_ = String(_loc4_.@type);
}
else if(this._instance[_loc4_.@nom] !== undefined)
{
if(this._instance[_loc4_.@nom] is Boolean)
{
_loc2_ = "boolean";
}
else if(this._instance[_loc4_.@nom] is Number)
{
_loc2_ = "number";
}
else if(this._instance[_loc4_.@nom] is int)
{
_loc2_ = "int";
}
else if(this._instance[_loc4_.@nom] is String)
{
_loc2_ = "string";
}
else if(this._instance[_loc4_.@nom] is Array)
{
_loc2_ = "array";
}
}
else
{
_loc2_ = "string";
}
switch(_loc2_)
{
case "boolean":
this._object[_loc4_.@nom] = this._instance[_loc4_.@nom] = String(_loc4_.@valeur) == "true" ? true : false;
break;
case "number":
this._object[_loc4_.@nom] = this._instance[_loc4_.@nom] = Number(_loc4_.@valeur);
break;
case "int":
this._object[_loc4_.@nom] = this._instance[_loc4_.@nom] = int(_loc4_.@valeur);
break;
case "array":
this._object[_loc4_.@nom] = this._instance[_loc4_.@nom] = String(_loc4_.@valeur).split(",");
break;
case "string":
this._object[_loc4_.@nom] = this._instance[_loc4_.@nom] = String(_loc4_.@valeur);
break;
}
}
}
}
}