XML driven object instancing and Array pushing
I used similar XML to make instances of class described in typing atributte of ogroup node.
<ogroup typing=”ifs.ifs3D.Camera” arrayName=”camArray” >
<ent camPos=”200,200,800? camTar=”0,0,0? camRot=”0,0,0? fov=”90? focus=”100? name=”maincam” />
</ogroup>
</root>
With small addaptation you can use following function (when XML data is already loaded and passed to function as input:XML).
output is refference to container object.
arrayName XML attribute telling to function in which array to push instanced object.
That means that your output object must have Array named as declared in XML attribute.
var countArrays:Number;
var countObjects:Number;
var ogroups:Number;
// creating array
var tempArray:Array = new Array();
// ogroups loop
for each (var property:XML in input.ogroup) {
var objectTyping:String = property.@typing;
var arrayName:String = property.@arrayName;
// if inserting successfull
if (output.hasOwnProperty(arrayName)) {
// instancing blank array
output[arrayName] = new Array();
// object loading loop
for each (var entry:XML in property.ent) {
var tmpClass:Object = getDefinitionByName(objectTyping);
var tempObj:Object = new tmpClass();
// checking if class has particular properties and if it has, applying values from XML
if (tempObj.hasOwnProperty(”iParent”)) {
tempObj.iParent = output;
}
if (tempObj.hasOwnProperty(”fromXMLentry”)) {
tempObj.fromXMLentry(entry);
}
output[arrayName].push(tempObj);
}
}
// object loading loop end
}
}
hasOwnProperty is very usefull method. In my case, almost all of classes that I’m instancing have iParent property and fromXMLentry():void method (this method sets other object’s properties from XML node (<ent />), but not all. In case where I havn’t used hasOwnProperty():Boolean method (inherited from Object Class, that means that every class has it) I’ll have runtime error when class declared in typing=”" attribute is without mentioned property/method.
July 2nd, 2010 at 3:08 pm
< blockquote >< a href=”http://pillspot.org/”>Pillspot.org. Canadian Health&Care.Best quality drugs.No prescription online pharmacy.Special Internet Prices. No prescription pills. Buy drugs online< /a >…
Buy:Nexium.Zovirax.Actos.Prevacid.Synthroid.Petcam (Metacam) Oral Suspension.Mega Hoodia.Prednisolone.Accutane.Valtrex.Human Growth Hormone.Arimidex.Lumigan.100% Pure Okinawan Coral Calcium.Retin-A.Zyban….
July 21st, 2010 at 6:36 am
< blockquote >< a href=”http://medicamentspot.com/”>MedicamentSpot.com. Canadian Health&Care.Special Internet Prices.Best quality drugs.No prescription online pharmacy. No prescription drugs. Buy drugs online< /a >…
Buy:Ventolin.Amoxicillin.Female Pink Viagra.Buspar.Acomplia.Lipitor.Benicar.Lasix.Lipothin.Cozaar.Seroquel.Zocor.Nymphomax.Wellbutrin SR.SleepWell.Aricept.Female Cialis.Zetia.Prozac.Advair….
August 29th, 2010 at 8:30 am
au digital camera/ http://ACEHARDWAREE.INFO/tag/r\x3dh : au digital camera/…
r\x3dh…
August 30th, 2010 at 2:13 am
alder http://bcheesecakep5u2.ANTIQUEFURNINISHING.INFO/tag/Maple+alder+kitchen/ : Maple…
kitchen…