2 Replies Latest reply on Mar 3, 2009 7:05 AM by chieffan

    call XML when button pressed

    chieffan Level 1
      I am pulling in some XML data that shows up in columns. Currently it is working I think how I want it when testing, the data is going to the correct column. What I want to do is extend this so when a button is clicked the correct column data is shown.

      var myXML:XML = new XML();
      myXML.ignoreWhite = true;
      myXML.load("rels.xml");
      myXML.onLoad = function(success) {
      if (!success) {
      trace("XML FAILED TO LOAD");
      } else {
      trace("XML LOADED");
      var totalButtons:Number = myXML.firstChild.childNodes.length;
      for (i=0; i<myXML.firstChild.childNodes.length; i++) {
      trace(myXML.firstChild.childNodes .attributes.id);
      var columnData = myXML.firstChild.childNodes
      ;
      //this pulls the values for the columns
      for (var j = 0; j<columnData.childNodes.length; j++) {
      _root["c"+j+"_txt"].htmlText = columnData.childNodes[j];

      }

      }

      }
      };

      XML is like this

      <stuff>

      <but id ="button1" >
      <column id ="1">test 1</column>
      <column id ="2">test 2</column>
      <column id ="3">test 3</column>
      </but>


      </stuff>

      I want to have a button for each node. So if I have five nodes, I want to create 5 buttons. I know how to do this via attachMovie from the library, but how do I tell it that button2 has been clicked? Where do I do that in my code? I want it to be when but2 is clicked it finds but2_mc ID in the XML and displays the column text for that data.

      initially I had this right before my for loop.

      for (b=1; b<=totalButtons; b++) {

      attachMovie("buttonSelection","but"+b,this.getNextHighestDepth());
      }

      Thanks for the help.
        • 1. Re: call XML when button pressed
          Level 7
          >> attachMovie("buttonSelection","but"+b,this.getNextHighestDepth());

          You can use an init object - just inject an id variable - b from your loop:

          attachMovie("buttonSelection","but"+b,this.getNextHighestDepth(),{ind:b});

          Do you assign your onRelease functions there too? Wherever you do just use
          this.ind to pass the buttons index along to some function:

          this["but" + b].onRelease = function(){ getMyXML(this.ind); }


          --
          Dave -
          www.offroadfire.com
          Adobe Community Expert
          http://www.adobe.com/communities/experts/


          • 2. Re: call XML when button pressed
            chieffan Level 1
            Thanks Dave. I feel I am almost there. the ind.b doesn't seem to be working. I was able to get my button to work but using _root instead of this. Any more pointers? Where does getMyXML(this.ind); this go?

            var myXML:XML = new XML();
            myXML.ignoreWhite = true;
            myXML.load("rels.xml");
            myXML.onLoad = function(success) {
            if (!success) {
            trace("XML FAILED TO LOAD");
            } else {
            trace("XML LOADED");
            var totalButtons:Number = myXML.firstChild.childNodes.length;


            //this determines the button
            for (i=0; i<myXML.firstChild.childNodes.length; i++) {
            trace(myXML.firstChild.childNodes .attributes.id);//returns but1_mc, etc
            var columnData = myXML.firstChild.childNodes
            ;
            //this pulls the values for the columns
            for (var j = 0; j<columnData.childNodes.length; j++) {

            _root["c"+j+"_txt"].htmlText = columnData.childNodes[j];

            }

            }
            for (b=1; b<=totalButtons; b++) {
            trace(totalButtons);
            attachMovie("test","but"+b,this.getNextHighestDepth(),{ind:b});
            _root["but"+b]._x = 0;
            _root["but"+b]._y = yPosition;
            yPosition = yPosition+25;
            _root["but"+b].onRelease = function() {
            getMyXML(this.ind);
            trace("ind "+this.ind)
            };
            }


            }
            };


            var yPosition = 0;