4 Replies Latest reply on Oct 26, 2008 5:57 PM by m_hartnett

    How to Add using Actionscript

    alice_data Level 1
      Hi,

      This may seem to be a simple problem, but I am not sure how to get the heads and tails from this. I have written up a code snippet that spits out the values based from the output from an external HTTPService. The variables I declared are integer types, but when I tried to calculate the total, it always outputs the "appended string" from the values I have in the XML. What I really want to see is that it outputs the "total" of the numbers I have in the for loop by adding it together.

      Is there something I have missed here?

      I tried doing something like number_lines = xmlList.number_lines so I don't have to worry about the index number of a particular element in the XML, but every time when I do this, I get no output f the number and messes up my code. Is there some way in which I can output the number based on the element name rather than the index position of it in the XML?

      Thanks in advance.

      To illustrate, I have attached the XML and Actionscript below:
        • 1. Re: How to Add using Actionscript
          Level 7

          "alice_data" <webforumsuser@macromedia.com> wrote in message
          news:ge261a$8is$1@forums.macromedia.com...
          > Hi,
          >
          > This may seem to be a simple problem, but I am not sure how to get the
          > heads and tails from this. I have written up a code snippet that spits out
          > the
          > values based from the output from an external HTTPService. The variables I
          > declared are integer types, but when I tried to calculate the total, it
          > always
          > outputs the "appended string" from the values I have in the XML. What I
          > really
          > want to see is that it outputs the "total" of the numbers I have in the
          > for
          > loop by adding it together.
          >
          > Is there something I have missed here?
          >
          > I tried doing something like number_lines = xmlList.number_lines so I
          > don't
          > have to worry about the index number of a particular element in the XML,
          > but
          > every time when I do this, I get no output f the number and messes up my
          > code.
          > Is there some way in which I can output the number based on the element
          > name
          > rather than the index position of it in the XML?
          >

          Everything in XML is text. Look at parseInt()

          HTH;

          Amy


          • 2. Re: How to Add using Actionscript
            alice_data Level 1
            Hi, Amy:

            Thanks for the heads up, but isn't the data in <category>203</category> a number?
            My next question is, if the information is considered text, but I can parse it by declaring [Bindable]private var total_incidence:int; in Actionscript, what would you recommend me change to make the calculation work?

            Thanks a lot for your help.

            Alice
            • 3. Re: How to Add using Actionscript
              Level 7

              "alice_data" <webforumsuser@macromedia.com> wrote in message
              news:ge30fk$cmu$1@forums.macromedia.com...
              > Hi, Amy:
              >
              > Thanks for the heads up, but isn't the data in <category>203</category>
              > a
              > number?

              No. It is a string containing a numeric value.

              > My next question is, if the information is considered text, but I can
              > parse
              > it by declaring [Bindable]private var total_incidence:int; in
              > Actionscript,

              I'd think that might cause an implicit coercion error.

              > what would you recommend me change to make the calculation work?

              Do a search in the docs for parseInt. If you still have questions, come
              back :-).


              • 4. Re: How to Add using Actionscript
                m_hartnett Level 3
                As Amy says the data form XML is considered string and it must be converted to the type you need.

                This will do it.
                new Number(xmlList .total_incidence);