PDA

View Full Version : Simplify XML AS3 Code



johanndm
July 4th, 2009, 06:46 AM
Hi,

I have to repeat the follow code 4x5 times currently....

t_factor = rc_xml.p.rc.(@id == t_type).pduration.pfactor;
t_base = rc_xml.p.rc.(@id == t_type).pduration.pbase;
t_min = rc_xml.p.rc.(@id == t_type).pduration.pmin;
t_start = rc_xml.p.rc.(@id == t_type).pduration.pstart;
t_end = rc_xml.p.rc.(@id == t_type).pduration.pend;

I'm trying to do the following:

var myArray_1:Array = new Array("pduration", "poutfit", "pbackground", "ppax");
var i:int = 0;

for (i=0; i<4; i++)
{
t_factor = rc_xml.p.rc.(@id == t_type).myArray_1[i].pfactor;
t_base = rc_xml.p.rc.(@id == t_type).myArray_1[i].pbase;
t_min = rc_xml.p.rc.(@id == t_type).myArray_1[i].pmin;
t_start = rc_xml.p.rc.(@id == t_type).myArray_1[i].pstart;
t_end = rc_xml.p.rc.(@id == t_type).myArray_1[i].pend;
}

PROBLEM is that Flash won't accept the VARIABLE myArray[i] in place of the element name?

Can someone please advise ;-)

Thanks,
Johann

dan89_eu
July 4th, 2009, 11:02 AM
try this:


var myArray_1:Array = new Array("pduration", "poutfit", "pbackground", "ppax");
var i:int = 0;

for (i=0; i<4; i++)
{
t_factor = rc_xml.p.rc.(@id == t_type).elements(myArray_1[i]).pfactor;
t_base = rc_xml.p.rc.(@id == t_type).elements(myArray_1[i]).pbase;
t_min = rc_xml.p.rc.(@id == t_type).elements(myArray_1[i]).pmin;
t_start = rc_xml.p.rc.(@id == t_type).elements(myArray_1[i]).pstart;
t_end = rc_xml.p.rc.(@id == t_type).elements(myArray_1[i]).pend;
}

johanndm
July 4th, 2009, 10:23 PM
Dan,

Thanks a million - I tried element and never got around to elements ;-)

Thanks once again for the help.