It code looks like it should work.  The only thing that I see as a 
possible problem is that AS is asyncronous.  myDP.addItem(item) 
might not be complete before calculateTotal() is called.  You might 
have to create a setter for the ArrayCollection that triggers 
calculateTotal().

-TH

--- In [email protected], "Tracy Spratt" <[EMAIL PROTECTED]> 
wrote:
>
> It looks ok, what exactly is not working?
> 
>  
> 
> Do the myDP[i].price and myDP[i].quantity expressions trace out 
values
> in the loop?
> 
>  
> 
> Tracy
> 
>  
> 
>  
> 
> ________________________________
> 
> From: [email protected] 
[mailto:[EMAIL PROTECTED] On
> Behalf Of s_hernandez01
> Sent: Tuesday, July 18, 2006 3:04 PM
> To: [email protected]
> Subject: [flexcoders] Actionscript Help
> 
>  
> 
> Hey could anyone tell me why this actionscript function does not 
work?
> I want to try and total the prices of all the items that get put 
into
> my shopping cart.
> 
> <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>
>






------------------------ Yahoo! Groups Sponsor --------------------~--> 
Something is new at Yahoo! Groups.  Check out the enhanced email design.
http://us.click.yahoo.com/SISQkA/gOaOAA/yQLSAA/nhFolB/TM
--------------------------------------------------------------------~-> 

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

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to