Either trace the values in the for loop or use the debugger to step through it to inspect the values.  Probably some evaluation of my DP[i].price or myDP[i].quantity is undefined, or null or maybe a string.  Any of those can make the total variable NaN.  Actually it is probably the String situation.  You may need to cast the values to some numeric type.  I haven’t checked to see if parseFloat() is still valid in AS3.

 

You just need to debug this to see what is going wrong.

 

Tracy

 


From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of s_hernandez01
Sent: Wednesday, July 19, 2006 11:51 AM
To: [email protected]
Subject: [flexcoders] Re: Actionscript Help

 

Well, I am still new to Flex so I'm having trouble understanding what
you all are saying. However, below is a link that has my app online
so you get an idea of what is going into the cart (just right click to
view the source). Now, I created a form below the datagrid that
totals all my items when they are dropped in the cart. I receive no
errors when saved, but when I run the app, it returns "NaN" in the
label of the form. Why would this occur and what approach do I need
to take to correct this error? Thanks for listening.

Sal

http://flex.work.iotashan.com/salShoppingCart/flexcodersHelp.html

> > <mx:Script>
> > <![CDATA[
> > import mx.collections.ArrayCollection;
> > import mx.events.IndexChangedEvent;
> > import mx.formatters.CurrencyFormatter;
> > import mx.effects.*;
> > import mx.core.*;
> > import mx.controls.NumericStepper;
> >
> > [Bindable]
> > public var myDP:ArrayCollection = new ArrayCollection();
> > [Bindable]
> > public var total:Number = 0;
> >
> > public function addItem(item:Object):void{
> > myDP.addItem(item);
> > calculateTotal();
> > }
> >
> > private function calculateTotal():void{
> > for (var i:int=0; i < myDP.length; i++) {
> > total += myDP[i].price * myDP[i].quantity;
> > }
> > }
> > ]]>
> > </mx:Script>
> >
> > <mx:DataGrid width="100%" textAlign="center" height="100%"
> > id="content" dropEnabled="true" dataProvider="{myDP}">
> > <mx:columns>
> > <mx:DataGridColumn headerText="" dataField="image"
> > itemRenderer="mx.controls.Image" width="25"/>
> > <mx:DataGridColumn headerText="Product" dataField="name"/>
> > <mx:DataGridColumn id="productQuantity" headerText="Qty"
> > dataField="quantity" rendererIsEditor="true"
> > itemRenderer="mx.controls.NumericStepper" editorDataField="value"/>
> > <mx:DataGridColumn id="productPrice" headerText="Price"
> > dataField="price"/>
> > </mx:columns>
> > </mx:DataGrid>
> >
> > <mx:Form verticalGap="0" paddingRight="0" borderStyle="outset">
> >
> > <mx:FormItem label="Total:" color="#ffffff" borderStyle="inset">
> >
> > <mx:Label id="extPrice" width="70" text="{total}"
> textAlign="right"/>
> >
> > </mx:FormItem>
> > </mx:Form>
> >
>

__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




__,_._,___

Reply via email to