1 Reply Latest reply on Oct 29, 2009 1:56 PM by kglad

    Adding variables together imported from xml?

    Matt_Quay_Design

      Hi Everyone,

       

      I have yet another problem that i cant seem to solve

       

      I have imported some info from an xml file into my movie. The info from this file is then displayed in dynamic text boxes. Three of these text boxes show a price which displays fine. However i need the contents of these text boxes to be added together in another dynamic text box called total. I need this total to update as the price fields change. I just cant figure it out.

       

      Here is my code which is placed at frame 1 of my movie:

       

      The last line of code is along the lines of how i think it should work, but i think its probably totally wrong

       

      stop();

      bar._visible = false;

      bar2._visible = false;

      bar3._visible = false;

      please_wait._visible = false;

       

      //Populate cart with default items from xml file//

       

      function CreateMenu(cart_xml){

      // start with the first item in the XML

      var items = cart_xml.firstChild.firstChild.childNodes; // menu -> menuitems -> child nodes array

      for (var i=0; i<items.length; i++) {

      // only continue if the type of this item is a squirrel

      if (items[i].attributes.type == "silver") {

       

      // create variables for our elements

      var componentlegs = items[i].firstChild; // same as items[i].childNodes[0]

      var colourlegs = items[i].childNodes[1]; // second child node

      var pricelegs = items[i].childNodes[2]; // second child node

      var componentbody = items[i].childNodes[3];

      var colourbody = items[i].childNodes[4];

      var pricebody = items[i].childNodes[5];

      var componentbezel = items[i].childNodes[6];

      var colourbezel = items[i].childNodes[7];

      var pricebezel = items[i].childNodes[8];

       

      // assign text using nodeValue to get the text

      legs_component.text = componentlegs.firstChild.nodeValue;

      legs_colour.text = colourlegs.firstChild.nodeValue;

      legs_price.text = pricelegs.firstChild.nodeValue;

      body_component.text = componentbody.firstChild.nodeValue;

      body_colour.text = colourbody.firstChild.nodeValue;

      body_price.text = pricebody.firstChild.nodeValue;

      bezel_component.text = componentbezel.firstChild.nodeValue;

      bezel_colour.text = colourbezel.firstChild.nodeValue;

      bezel_price.text = pricebezel.firstChild.nodeValue;

       

       

      }

      }

      }

       

      // manage XML

      // create new XML object instance, remembering to ignore white space

      var cart_xml = new XML();

      cart_xml.ignoreWhite = true;

      // define an onLoad to create our location menu when the XML has successfully loaded.

      cart_xml.onLoad = function(success){

      if (success) CreateMenu(this);

      else trace("Error loading XML file"); // no success?  trace error (wont be seen on web)

      }

      // load the xml file!

      cart_xml.load("cart.xml");

       

       

       

      total = (Number(pricelegs))+(Number(pricebody))+(Number(pricebezel));

       

       

      Thank you in advance for any replies to my dilemma!

       

      Cheers

       

      Matt

        • 1. Re: Adding variables together imported from xml?
          kglad Adobe Community Professional & MVP

          try:

           


           

           

          stop();

          bar._visible = false;

          bar2._visible = false;

          bar3._visible = false;

          please_wait._visible = false;

           

          //Populate cart with default items from xml file//

           

          function CreateMenu(cart_xml){

          // start with the first item in the XML

          var items = cart_xml.firstChild.firstChild.childNodes; // menu -> menuitems -> child nodes array

          for (var i=0; i<items.length; i++) {

          // only continue if the type of this item is a squirrel

          if (items[i].attributes.type == "silver") {

           

          // create variables for our elements

          var componentlegs = items[i].firstChild; // same as items[i].childNodes[0]

          var colourlegs = items[i].childNodes[1]; // second child node

          var pricelegs = items[i].childNodes[2]; // second child node

          var componentbody = items[i].childNodes[3];

          var colourbody = items[i].childNodes[4];

          var pricebody = items[i].childNodes[5];

          var componentbezel = items[i].childNodes[6];

          var colourbezel = items[i].childNodes[7];

          var pricebezel = items[i].childNodes[8];

           

          // assign text using nodeValue to get the text

          legs_component.text = componentlegs.firstChild.nodeValue;

          legs_colour.text = colourlegs.firstChild.nodeValue;

          legs_price.text = pricelegs.firstChild.nodeValue;

          body_component.text = componentbody.firstChild.nodeValue;

          body_colour.text = colourbody.firstChild.nodeValue;

          body_price.text = pricebody.firstChild.nodeValue;

          bezel_component.text = componentbezel.firstChild.nodeValue;

          bezel_colour.text = colourbezel.firstChild.nodeValue;

          bezel_price.text = pricebezel.firstChild.nodeValue;

          total = (Number(pricelegs.firstChild.nodeValue))+(Number(pricebody.firstChild.nodeValue))+(Number (pricebezel.firstChild.nodeValue));

           

           

          }

          }

          }

           

          // manage XML

          // create new XML object instance, remembering to ignore white space

          var cart_xml = new XML();

          cart_xml.ignoreWhite = true;

          // define an onLoad to create our location menu when the XML has successfully loaded.

          cart_xml.onLoad = function(success){

          if (success) CreateMenu(this);

          else trace("Error loading XML file"); // no success?  trace error (wont be seen on web)

          }

          // load the xml file!

          cart_xml.load("cart.xml");