A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Numbers and XML

  1. #1
    Junior Member
    Join Date
    Aug 2003
    Posts
    2

    Numbers and XML

    Okay here's the actionscript I am dealing with:
    Code:
    stop();
    var NumChoice1 = undefined;
    var NumChoice2 = undefined;
    var NumChoice3 = undefined;
    var NumChoice4 = undefined;
    var TotalVotes = undefined;
    
    	poll_xml = new XML();
    	poll_xml.contentType = "text/xml";
    	poll_xml.ignoreWhite = true;
    	poll_xml.load('poll.xml');
    
    
    function onResults() {
    	NumChoice1 = poll_xml.firstChild.childNodes[0].firstChild.nodeValue.toString;
    	NumChoice2 = poll_xml.firstChild.childNodes[1].firstChild.nodeValue;
    	NumChoice3 = poll_xml.firstChild.childNodes[2].firstChild.nodeValue;
    	NumChoice4 = poll_xml.firstChild.childNodes[3].firstChild.nodeValue;
    	TotalVotes = NumChoice1 + NumChoice2 + NumChoice3 + NumChoice4;
    
    	trace ("TotalVotes = " + TotalVotes);
    	nextFrame();
    }
    And here's the xml I'm dealing with:
    PHP Code:
    <Choices url="http://kungfudrew.com/poll.xml">
        <
    choice1>20</choice1>
        <
    choice2>2</choice2>
        <
    choice3>3</choice3>
        <
    choice4>4</choice4>    
    </
    Choices
    Now the trace TotalVotes will give me 20234 instead of 29. How can I convert these values (NumChoiceX) to numeric values?
    Last edited by WilfCarter; 11-05-2003 at 09:12 PM.

  2. #2
    Senior Member tupps's Avatar
    Join Date
    Jan 2001
    Location
    Melbourne
    Posts
    2,035
    You are actually joining strings together, use

    TotalVotes = Number(NumChoice1) + Number(NumChoice2) + Number(NumChoice3) + Number(NumChoice4);
    Flash-XML FAQ
    http://www.tupps.com/flash/faq/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center