PDA

View Full Version : dynamic variable names, set() and eval() as2 to as3


pinkeye
02-27-2008, 06:17 PM
hello

i've been trying to rewrite this code (it's from flash 8 tutorial) in as3. the problems started with phrasing xml file. here's what i did so far.

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, loadXML);
loader.load(new URLRequest("menu_nav.xml"));
var ID:Array = new Array;
var DisplayName:Array = new Array;
var LinkType:Array = new Array;
var LinkValue:Array = new Array;
var topMenuNum = 0;

function loadXML(e:Event):void

{

var xml:XML = new XML(e.target.data);

trace ("the number of total children is... " + xml.children().length());

var i = 0;
while ( i < xml.children().length()) {

ID.push(xml.children()[i].attributes()[0]);
DisplayName.push(xml.children()[i].attributes()[1]);
LinkType.push(xml.children()[i].attributes()[2]);
LinkValue.push(xml.children()[i].attributes()[3]);

if (ID[i] == "TM") {

topMenuNum = topMenuNum +1;
}



i = i +1;

}

trace ("the total number of top menu items is... " + topMenuNum);

}now i have some serious problems with this part (it should be before i=i+1). it's to keep track of how many submenu items there will be.

set ("submenu_Finish_" + ID[i] , i);
if ( eval(".submenu_Start_" + ID[i]) == undefined )
{
set ("submenu_Start_" + ID[i] , i);
Total_subs = Total_subs + 1;
}

set ("Total_Items_in_Submenu_" + ID[i] , eval( "submenu_Finish_" + ID[i]) - eval( "submenu_Start_" + ID[i]) + 1);there was _global in front of every variable. i removed it coz i dont think it would affect the code at this point