0 Replies Latest reply on Dec 7, 2006 12:38 PM by BazaarMan

    dynamically assigning variable in xml loop

    BazaarMan
      I am trying to dynamically assign a variable name so I can build an accordian nav from and XML doc. the code looks like this:


      ACnav['depthChild0']._alpha = 0;
      ACnav.setStyle("color", 0x0ffffff);

      ACnav.setStyle ("openEasing", mx.transitions.easing.strong.easeout);
      ACnav.setStyle ("selectionDuration", mx.transitions.duration.slow);

      navXML = new XML();
      navXML.ignoreWhite = true;
      navXML.load("menu1.xml");
      oY=5;
      var currentSection = 0;

      function buildNav () {
      DisposableXML = new XML();
      TempXML = new XML();
      button = new Array();
      //buttonNum = new Array();
      subitem = new Array();
      menuItem = new Array();
      o = new Array ();
      subitemlocation = new Array();
      DisposableList = new Array();
      buttonList = navXML.firstChild.childNodes;
      i = 0;
      sectionLength = buttonList.length;
      while (i<=buttonList.length) {
      if (buttonList .nodeName.toLowerCase() == "button") {
      DisposableXML = buttonList
      ;
      DisposableList = DisposableXML.childNodes;
      buttonName = buttonList .attributes.name;
      set ("buttonNum", "buttonNumber"+i);
      trace(buttonNum);

      ii = 0;
      //trace(buttonName+"-"+buttonNum);
      //ACnav.createChild("View", buttonNum, {label: buttonName, icon: "mainNav"});
      button
      = ACnav.createChild("View", buttonNum, {label: buttonName, icon: "mainNav"});
      oY=5
      while (ii<=DisposableList.length) {
      TempXML = DisposableList[ii];
      if (DisposableList[ii].nodeName.toLowerCase() == "subitem") {
      subitem = TempXML.attributes.name;
      //subitemlocation = TempXML.attributes.location;
      subitemNum="subitemNum"+[ii]+ ;
      //trace(buttonNum+"-"+subitemNum+"-"+subitem);
      menuItem
      = ACnav.buttonNum.createChild("subNav", subitemNum, {childText: subitem});
      menuItem .move(0, oY);
      oY=(oY+25);
      //trace(buttonNum);
      }
      ii = Number(ii)+1;

      }
      }
      i = Number(i)+1;
      }
      //trace(button);
      trace(menuItem);
      redraw();
      //gotoAndPlay('reload');
      }

      The problem lies with this line: button
      = ACnav.createChild("View", buttonNum, {label: buttonName, icon: "mainNav"});

      If I quote the "buttonNum", it works, but jumbles the subnav items together vs in the proper node. I need to have that declared dynamically so that each parent node has a differentID and then createchild goes under that. Anyway, I've tried alot of stuff over the last few days and its getting frustrating.

      Thanks for the help if anyone contributes!