Adobe Dreamweaver Forums



Last 10 THreads :         CreateODBCDate and cfqueryparam with cf_sql_date (Last Post : hannibalcanibal - Replies : 0 - Views : 1 )           »          Load bmp images in a flex app (Last Post : eholz1 - Replies : 0 - Views : 1 )           »          Problem with "Title" and DW CS4 (Last Post : Murray *ACE* - Replies : 1 - Views : 2 )           »          Snippet Pod Problems (Last Post : Pat@ffic - Replies : 2 - Views : 3 )           »          DDX generated PDF Table of Contents issue (Last Post : Flashm@n - Replies : 0 - Views : 1 )           »          Array of Queries (Last Post : ptrott - Replies : 3 - Views : 4 )           »          image alignment (Last Post : alexander glomba - Replies : 0 - Views : 1 )           »          Importing Iweb to Dreamweaver (Last Post : tllearner - Replies : 2 - Views : 3 )           »          How to I get an FLV Skin to display on external sites? (Last Post : QADesign - Replies : 0 - Views : 1 )           »          Spry menu bar with a different image for each item? (Last Post : bongalook - Replies : 0 - Views : 1 )           »         


User Info Statistics
Go Back   Adobe Dreamweaver Forums > Macromedia Software > Flex
 
Tags:



Reply
  #1 (permalink)  
Old 11-03-2008, 04:38 AM
alice_data
 
Posts: n/a
Diggs:
Default How to Add using Actionscript

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:

XML:

<?xml version="1.0" encoding="utf-8" ?>
<log>
<number_lines>2</number_lines>
<sell_manager>
<category>203</category>
<total_incidence>3</total_incidence>
</sell_manager>
<sell_manager>
<category>204</category>
<total_incidence>11</total_incidence>
</sell_manager>
</time_log>

Actionscript:

[Bindable]private var total_incidence:int;
[Bindable]private var number_lines:String;

private function resultHandler(e:ResultEvent):void {

var xmlList:XMLList = new XML(e.result).children();
number_lines = xmlList[0];
total_incidence= xmlList[i].total_incidence;
for (var i=1; i<= number_lines; i++) {
total_incidence += xmlList[i].total_incidence;
Alert.show("There are " + total_incidence + " of
sales","Alert Box");
}
}



Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-03-2008, 04:38 AM
Amy Blankenship
 
Posts: n/a
Diggs:
Default Re: How to Add using Actionscript


"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


Reply With Quote
  #3 (permalink)  
Old 11-03-2008, 04:38 AM
alice_data
 
Posts: n/a
Diggs:
Default Re: How to Add using Actionscript

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


Reply With Quote


  #4 (permalink)  
Old 11-03-2008, 04:38 AM
Amy Blankenship
 
Posts: n/a
Diggs:
Default Re: How to Add using Actionscript


"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 :-).


Reply With Quote
  #5 (permalink)  
Old 11-03-2008, 04:38 AM
mhartnett
 
Posts: n/a
Diggs:
Default Re: How to Add using Actionscript

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[i].total_incidence);
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 11:05 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Cheap Car Insurance - Compare Motor Insurance
Endsleigh Car Insurance Natwest Car Insurance
More Than Car Insurance Norwich Union Car Insurance
Prudential Car Insurance Zurich Car Insurance
Inactive Reminders By Mished.co.uk