1 Reply Latest reply on Oct 23, 2007 9:28 AM by clbeech

    Need help in looping function

    AScracker Level 1
      in this code i am fetching the details from the xml....
      after that using addData() function i am producing the xml....
      but in the getetailsfrmXML() i am using for loop for 60times ..so if i used the addData() function then it produced 60times result... so it make my system slow...

      i need to get the all data from xml with single loop...

      public function getetailsfrmXML(details) {
      var __SeatingDetails:XML = new XML();
      __SeatingDetails.parseXML(details);
      var my_array:Array = new Array();
      var totalElements = XPath.selectNodes(__SeatingDetails, "//Employee/");
      for (var i = 0; i<=60; i++) {
      var currentNode:XMLNode = totalElements ;
      EmpName = currentNode.attributes.Empname;
      SeatNumber = currentNode.attributes.SeatNumber;
      prjName = currentNode.attributes.ProjectName;
      pmName = currentNode.attributes.PM;
      PamName = currentNode.attributes.PAM;
      var emp:String = EmpName+"_"+String(SeatNumber)+"_"+prjName+"_"+pmName+"_"+PamName;
      my_array.push(emp);
      addData(EmpName, SeatNumber, prjName, pmName, PamName);
      }

      }
      public function addData(Empname:String, SNumber:Number, ProjectName:String, Pmname:String, PamName:String) {
      var Employee:XMLNode = __Employee_xml.createElement("Employee");
      Employee.attributes.empname = Empname;
      Employee.attributes.seatnumber = SNumber;
      Employee.attributes.prjName = ProjectName;
      Employee.attributes.PMName = Pmname;
      Employee.attributes.PAMName = PamName;
      __Employee_xml.firstChild.appendChild(Employee);
      trace("__Employee_xml "+__Employee_xml);
      }
        • 1. Re: Need help in looping function
          clbeech Level 3
          AS, first, use the attach code option to add your code on the forum.

          second, use the' getetailsfrmXML()' function to 'load' the XML, then 'separately' use the 'addData()' function only when you are creating a single new entry, probably trigger from a submit button or something from a form you've created for a new user to enter information. so take the addData function out of the onLoad handler. If you are trying to place the information retrieved fromt he XML into something you can use, then create a new object in the lnLoad handler, add the information to new properties of the object, then store the object in an array.

          just for starters :)