1 Reply Latest reply on Jun 25, 2008 1:21 PM by bhnh

    How to populate list component via xml file?

      There is a TextArea component that should show the name and the description of the item selected in the list component. But I dont know how to populate list with external XML and what should be the coding in flash as well as what should be written in the XML. Please help.
        • 1. Re: How to populate list component via xml file?
          Here's an xml file listing a couple of brother comedy teams:
          <?xml version="1.0" encoding="UTF-8"?>

          Open a new .fla and save it in the same folder as the .xml file. Place a List Component on the Stage and name it (in this case, "comicTeams_list"). In the first frame write the following ActionScript:

          //create XML object and load external xml file
          var broList:XML = new XML();
          broList.ignoreWhite = true;
          broList.onLoad = processList; // this is a function that will be written below

          function processList(success:Boolean):Void{
          trace("Load failure");

          function loadList():Void{
          var broName:String;
          var listEntries = broList.firstChild.childNodes[0].childNodes[0].childNodes.length;
          for(var i:Number = 0;i<listEntries;i++){
          broName = broList.firstChild.childNodes[0].childNodes[0].childNodes .childNodes[0].nodeValue;

          //to make something happen when you click on a name in the List, create a Listener and function
          var broListListener:Object = new Object();
          broListListener.change = someAction; //"someAction" is a function to be written shortly
          //add the Listener to the List
          comicTeams_list.addEventListener("change", broListListener);

          function someAction(evtObj:Object):Void{
          var pickedBrother:String = evtObj.target.selectedItem.label;
          //write actions here, referencing pickedBrother variable

          The names of the Marx Brothers will appear in the box.

          This is written in AS2. When you post a question, it's a good idea include which version of ActionScript you're using.