1 Reply Latest reply on Dec 1, 2006 2:09 PM by I tried

    Help Creating Array

    champion25 Level 1
      I want to create a dynamic biography page that pulls in data from an XML file for multiple biography's. Can anyone help me with instruction on how to create an array that loads only one bio at a time on the press of a button, and when the next button is pressed it loads the next bio? Attached is the script and the XML.

      Any help would be greatly appreciated!
        • 1. Re: Help Creating Array
          I tried Level 1
          My best suggestion for the xml would be to do a search on xfactorstudio on the internet, download the classes and find a tutorial. Those classes make it very easily to build the array that you want. As for the rest of the script, I'd create a placeholder variable to keep track of where you are in the array. When the user clicks a button, just display the contents of the next element in the array and increment your placeholder variable by one.

          var bio:Array = new Array();
          var nCurrentbio:Number = 0;
          var owner = this;
          var tb:TextField;

          btn.onRelease = Function():Void{
          owner.loadNextBio();
          }

          function loadNextBio(){
          nCurrentbio++;
          tb.htmlText = bio[nCurrentbio];
          }

          You'll have to adapt this code, but that's the basic principle. You'll probably want to add some logic in the loadNextBio function to ensure that if it reaches the end of the array, it starts back over at the beginning.

          Good luck
          Robert