1 Reply Latest reply on Jun 3, 2008 1:26 AM by Noelbaland

    Populating Accordion by XML file

    248275
      Can anyone tell me how to populate an Accordion via XML file?
        • 1. Re: Populating Accordion by XML file
          Noelbaland Level 1
          Hello,

          There many ways of creating content to go inside accordion panels. This is a simple one that uses the Label component.

          Lets say you have an Accordion component on the stage with an instance name of "myAccordion". Drag a Label component onto the stage and then delete it. We just want the instance in our library so that we can reference it with Actionscript.
          The following script would go into frame 1 of an "actions" layer.

          myXML = new XML();
          myXML.ignoreWhite = true;
          myXML.load("movies.xml");

          myXML.onLoad = function(success)
          {
          if(success){
          var movies:Number = myXML.firstChild.childNodes.length;
          for(var n=0; n<movies; n++)
          {
          var movieName:String = myXML.firstChild.childNodes[n].attributes.title;
          var movieStars:String = myXML.firstChild.childNodes[n].attributes.stars;
          var movie:Object = myAccordion.createChild("Label", n, {label:movieName});
          movie.text = movieStars;

          }
          } else {
          trace("Error");
          }
          }

          [XML File: movies.xml]

          <?xml version="1.0" encoding="utf-8"?>
          <movies>
          <film title="ET" stars="Henry Thomas" />
          <film title="Star Wars" stars="Mark Hamill" />
          <film title="Close Encounters of the Third Kind" stars="Richard Dreyfus" />
          <film title="Raiders of the Lost Ark" stars="Harrison Ford" />
          <film title="Jaws" stars="Roy Schnieder" />
          <film title="Saving Private Ryan" stars="Tom Hanks" />
          </movies>

          Hope that helps