1 Reply Latest reply on Apr 9, 2007 9:55 AM by createmedia

    Reference Array attribute?

      Hi All,

      I am trying to reference an Array variable from an XML file import......and place that value in a text field.... But, am going a bit crazy trying to figure it out.... Just the basic syntax ... :-(

      Well, here's the page online. http://www.nmvinc.com/projects/testGallery/ccmprofile.html

      I'm importing two XML files... One to build the values in the List box.... One to load the images in the Gallery.
      But my only issue is referencing one of the values in the "people.xml" file .... The image gallery works fine.
      I'm trying to put the "desc" attribute value of the peopleArray from "people.xml" file .....and put that value into the NameTitle textfield.
      The problem area is commented below :

      Here is the code in the flash file :


      myGallery.contentXML = "test.xml";

      // xml playlist
      // create an XMl object
      var peepList:XML = new XML();
      // ignore white spaces
      peepList.ignoreWhite = true;
      peepList.onLoad = function() {
      // put the nodes of xml into array
      var peopleArray:Array = this.firstChild.childNodes;
      // iterate through people array
      // and add people to the listbox
      for (var i = 0; i<peopleArray.length; i++) {
      peopleList.addItem(peopleArray .attributes.desc, peopleArray.attributes.xmlFile, peopleArray .attributes.dept);
      // when xml is loaded play first item
      // highlight first person in listbox
      peopleList.selectedIndex = 0;
      // create a listener that responds
      // to changes in the listbox
      var peepListener:Object = new Object();
      peepListener.change = function() {
      // play the item selected in listbox
      myGallery.contentXML =(peopleList.getItemAt(peopleList.selectedIndex).data);

      // here is where the problem is : putting the dept value inside the NameTitle textfield.
      //NameTitle.text = code for dept attribute here ;

      // register the event listener to listbox
      peopleList.addEventListener("change", peepListener);
      // load xml file

      The "people.xml" file is :

      <?xml version="1.0" encoding="ISO-8859-1" ?>
      <person xmlFile="test.xml" desc="Shane Dee" dept="Project Manager" />
      <person xmlFile="person2.xml" desc="Person 2" dept="Engineering" />

      Thanks for any help you can give :-)
        • 1. Re: Reference Array attribute?
          createmedia Level 1
          Well, from reading I discovered I can't add another field from the XML file to the addItem() method...
          as such :

          peopleList.addItem(peopleArray .attributes.desc, peopleArray.attributes.xmlFile, addAnotherField? );

          But that addItem is for adding ' label, item ' ... such as :
          peopleList.addItem(peopleArray .attributes.desc, peopleArray.attributes.xmlFile);

          However, am still not sure how to reference another item in the XML file I have listed... want to access the "dept" node of a particular record...and put that into a text field... :-(

          Not really any closer but at least I know addItem won't really hep me