Hey Flexers I am having trouble creating a function that would total all the items added to my shopping cart. If anybody can help me out with my code, I'd appreciate it. I am still new to flex and don't know much of actionscript 3 so any advice would help me out alot. Below is a link to the shopping cart app(right click if you want to view the source) and the code below it, is the code of my shopping cart which has the calculateTotal() function that I tried to do to calculate the added items.
Thanks Sal http://flex.work.iotashan.com/salShoppingCart/flexcodersHelp.html <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <![CDATA[ import mx.collections.ArrayCollection; [Bindable] public var myDP:ArrayCollection = new ArrayCollection(); [Bindable] public var total:Number = 0; [Bindable] public var itemCount:int = 0; public function addItem(item:Object):void{ myDP.addItem(item); calculateTotal(); } public function calculateTotal():void{ var t:Number = 0; var c:Number = 0; var n:int = myDP.length; for (var i:int = 0; i < n; i++){ c += myDP[i].quantity; t += myDP[i].quantity * myDP[i].price; } total = t; itemCount = c; } ]]> </mx:Script> <mx:Panel width="100%" height="100%" layout="absolute" title="Shopping Cart"> <mx:VBox x="0" y="0" width="100%" height="100%"> <mx:DataGrid x="0" y="0" id="dg" width="100%" height="100%" dropEnabled="true" dataProvider="{myDP}"> <mx:columns> <mx:DataGridColumn headerText="Product" dataField="name"/> <mx:DataGridColumn id="productQuantity" headerText="Quantity" dataField="qty"/> <mx:DataGridColumn id="productPrice" headerText="Price" dataField="price"/> </mx:columns> </mx:DataGrid> <mx:Form verticalGap="0" paddingRight="0" borderStyle="outset"> <mx:FormItem label="Total:" borderStyle="inset" fontWeight="bold"> <mx:Label width="70" text="{total}" textAlign="right"/> </mx:FormItem> <mx:FormItem label="Shipping:" borderStyle="inset" fontWeight="bold"> <mx:Label width="70" textAlign="right"/> </mx:FormItem> <mx:FormItem label="Grand Total:" fontWeight="bold" borderStyle="inset"> <mx:Label width="70" textAlign="right"/> </mx:FormItem> </mx:Form> </mx:VBox> </mx:Panel> </mx:Canvas> -- 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/

