Thanks everyone, all your advise was really helpful and the function
is working like I want it to! Much props, thanks again! 

-Sal

--- In [email protected], "Dustin Mercer" <[EMAIL PROTECTED]>
wrote:
>
> There is some inefficiencies in this code, but this does work and its
> code to help you get started. 
> 
>  
> 
> <?xml version="1.0" encoding="utf-8"?>
> 
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> layout="vertical"
> 
>             creationComplete="doCreationComplete();">
> 
>             
> 
>             <mx:Script>
> 
>                         <![CDATA[
> 
>                                     import
> mx.controls.listClasses.BaseListData;
> 
>                                     import mx.events.CollectionEvent;
> 
>                                     import
> mx.collections.ArrayCollection;
> 
>                                     
> 
>                                     [Bindable] private var items :
> ArrayCollection;
> 
>                                     [Bindable] private var totalItems :
> int = 0;
> 
>                                     [Bindable] private var totalPrice :
> Number = 0;
> 
>                         
> 
>                                     private function
> doCreationComplete() : void {
> 
>                                                 items = new
> ArrayCollection();
> 
>  
> items.addEventListener(CollectionEvent.COLLECTION_CHANGE, updateTotal );
> 
>                                                 
> 
>                                                 var len : uint = 100;
> 
>                                                 while (len--) {
> 
>                                                             var item :
> Object = new Object();
> 
>                                                             item.label =
> "Item " + len;
> 
>                                                             item.qty =
> 1;
> 
>                                                             item.price =
> Math.round(Math.random() * 100);
> 
>  
> items.addItem(item);
> 
>                                                 }
> 
>                                     }
> 
>                                     
> 
>                                     private function updateTotal( event
> : CollectionEvent ) : void {
> 
>                                                 totalPrice = 0;
> 
>                                                 totalItems = 0;
> 
>                                                 
> 
>                                                 for (var i : int =
> 0;i<items.length;i++) {
> 
>                                                             var item :
> Object = items.getItemAt(i);
> 
>                                                             totalItems
> += item.qty;
> 
>                                                             totalPrice
> += item.qty * item.price;
> 
>                                                 }
> 
>                                     }
> 
>                         ]]>
> 
>             </mx:Script>
> 
>             
> 
>             <mx:Label text="{totalItems}" />
> 
>             <mx:Label text="{totalPrice}" />
> 
>             
> 
>             <mx:DataGrid dataProvider="{items}" width="100%"
> height="100%" editable="true">
> 
>                         <mx:columns>
> 
>                                     <mx:DataGridColumn dataField="label"
> />
> 
>                                     <!--mx:DataGridColumn
> dataField="qty" itemEditor="mx.controls.NumericStepper"
> editorDataField="value" /-->
> 
>                                     <mx:DataGridColumn dataField="qty"
> editorDataField="value">
> 
>                                                 <mx:itemEditor>
> 
>  
> <mx:Component>
> 
>  
> <mx:NumericStepper>
> 
>  
> <mx:Script>
> 
>  
> <![CDATA[
> 
>  
> import flash.events.Event;
> 
>  
> import mx.controls.DataGrid;
> 
>  
> 
> 
>  
> override protected function initializationComplete():void {
> 
>  
> super.initializationComplete();
> 
>  
> addEventListener( Event.CHANGE, updateDP );
> 
>  
> }
> 
>  
> 
> 
>  
> private function updateDP( event : Event ) : void {
> 
>  
> data.qty = value;
> 
>  
> DataGrid(listData.owner).dataProvider.itemUpdated(data);
> 
>  
> }
> 
>  
> ]]>
> 
>  
> </mx:Script>
> 
>  
> </mx:NumericStepper>
> 
>  
> </mx:Component>
> 
>                                                 </mx:itemEditor>
> 
>                                     </mx:DataGridColumn>
> 
>                                     <mx:DataGridColumn dataField="price"
> />
> 
>                         </mx:columns>
> 
>             </mx:DataGrid>
> 
>             
> 
> </mx:Application>
> 
>  
> 
>  
> 
> ________________________________
> 
> From: [email protected] [mailto:[EMAIL PROTECTED] On
> Behalf Of s_hernandez01
> Sent: Thursday, November 02, 2006 1:49 PM
> To: [email protected]
> Subject: [flexcoders] Re: Event Listener Help!!!
> 
>  
> 
> Thanks guys, I believe I would want the total to update itself as the
> user is changing the quantity, and not when they finish editing, but
> it's a temporary solution though. I didn't think about the editing
> part since I was stressing on the change event. If anyone else knows
> how I can code up the change event to my ArrayCollection in a datagrid
> so that the total gets updated promptly, PLEASE PLEASE PLEASE HELP ME!!!
> 
> 
> -Sal
> 
> --- In [email protected] <mailto:flexcoders%40yahoogroups.com>
> , "Doug Lowder" <douglowder@> wrote:
> >
> > You can use the grid's itemEditEnd handler to update the total after 
> > the user has finished editing the item. Also, set the grid's 
> > editable property to true and each column's editable property as 
> > desired.
> > 
> > If you want to actively track changes to the editor as the user 
> > makes them instead of after the user has finished editing the item, 
> > you may need to break the NumericStepper out as a component, and use 
> > the change event to trigger your function.
> > 
> > <mx:DataGrid id="grid" dataProvider="{myDP}" editable="true" 
> > textAlign="center"
> > itemEditEnd="callLater(calculateTotal)">
> > <mx:columns>
> > <mx:DataGridColumn headerText="Product" dataField="name" 
> > editable="false"/>
> > <mx:DataGridColumn id="qtyChanger" headerText="Qty" 
> > dataField="qty" 
> > rendererIsEditor="true" 
> > itemRenderer="mx.controls.NumericStepper" editorDataField="value"/>
> > <mx:DataGridColumn headerText="Price" dataField="price" 
> > editable="false"/>
> > </mx:columns>
> > </mx:DataGrid>
> > 
> > 
> > --- In [email protected]
> <mailto:flexcoders%40yahoogroups.com> , "s_hernandez01" 
> > <s_hernandez01@> wrote:
> > >
> > > Can anyone tell me how I can get my event listener to update the 
> > total
> > > when the quantity is changed using the numericStepper inside a 
> > datagrid? 
> > > 
> > > Thanks
> > > 
> > > Sal
> > > 
> > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
> <http://www.adobe.com/2006/mxml> "
> > > layout="absolute" xmlns="*" creationComplete="calculateTotal()">
> > > 
> > > 
> > > [Bindable]
> > > public var total:Number=0;
> > > [Bindable]
> > > public var numProducts:int=0;
> > > [Bindable]
> > > public var myDP:ArrayCollection = new ArrayCollection();
> > > 
> > > public function calculateTotal():void{
> > > var t:Number = 0;
> > > var n:Number = 0;
> > > for(var i:int = 0; i < myDP.length; i++){
> > > n += myDP[i].qty;
> > > t += myDP[i].price * myDP[i].qty;
> > > }
> > > total = t;
> > > numProducts = n;
> > > }
> > > 
> > > public function qtyChangeListener():void{
> > > qtyChanger.addEventListener("change", calculateTotal);
> > > }
> > > 
> > > <mx:DataGrid id="grid" dataProvider="{myDP}" textAlign="center">
> > > <mx:columns>
> > > <mx:DataGridColumn headerText="Product" dataField="name"/>
> > > <mx:DataGridColumn id="qtyChanger" headerText="Qty" dataField="qty"
> > > rendererIsEditor="true" itemRenderer="mx.controls.NumericStepper"
> > > editorDataField="value"/>
> > > <mx:DataGridColumn headerText="Price" dataField="price"/>
> > > </mx:columns>
> > > </mx:DataGrid>
> > > 
> > > <mx:Text text="{total}"/>
> > > 
> > > </mx:Application>
> > >
> >
>





--
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/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/flexcoders/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[EMAIL PROTECTED] 
    mailto:[EMAIL PROTECTED]

<*> 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