|
Here is an example app: <?xml version="1.0"
encoding="utf-8"?> <mx:Application
xmlns:mx="http://www.macromedia.com/2003/mxml" initialize="sortSetDP()"> <mx:Script> <![CDATA[
/************************************************************************************* */ private function
sortSetDP(sMode:String):Void { var aTemp:Array =
aApplesMaster.concat(); switch (sMode) { case
"top": aTemp.sort(cfAppleSales,Array.DESCENDING
); dgAppleSales.dataProvider
= aTemp.splice(0,3); dgAppleSales.rowCount
= aTemp.length; break; case
"bottom": aTemp.sort(cfAppleSales
); dgAppleSales.dataProvider
= aTemp.splice(0,3); dgAppleSales.rowCount
= aTemp.length; break; default: dgAppleSales.dataProvider
= aApplesMaster; dgAppleSales.rowCount
= aApplesMaster.length; break; } }//sortSetDP
/************************************************************************************* Compare function. Receives two
array elements as arguments */ private function
cfAppleSales(oElementA:Object,oElementB:Object):Number { var nQtyA:Number =
oElementA.qty; //get the A element quantity value var nQtyB:Number =
oElementB.qty; //get the B element quantity value if (nQtyA >
nQtyB) { //compare the
quantity values, and return the appropriate value return
1; } else if (nQtyB
> nQtyA) { return
-1; } return 0; }//cfAppleSales ]]> </mx:Script> <mx:Array
id="aApplesMaster"> <mx:Object>
<label>Shopper1</label> <qty>5</qty> </mx:Object> <mx:Object>
<label>Shopper2</label> <qty>7</qty> </mx:Object> <mx:Object>
<label>Shopper3</label> <qty>0</qty> </mx:Object> <mx:Object>
<label>Shopper4</label> <qty>4</qty> </mx:Object> <mx:Object>
<label>Shopper5</label> <qty>1</qty> </mx:Object> <mx:Object>
<label>Shopper6</label> <qty>0</qty> </mx:Object> <mx:Object>
<label>Shopper7</label> <qty>0</qty> </mx:Object> <mx:Object>
<label>Shopper8</label> <qty>0</qty> </mx:Object> </mx:Array> <mx:HBox> <mx:VBox> <mx:Button
label="Show Top Three Customers" height="30"
click="sortSetDP('top')"/> <mx:Button
label="Show Bottom Three Customers" height="30"
click="sortSetDP('bottom')"/> <mx:Button
label="Show All Customers" height="30"
click="sortSetDP('all')"/> </mx:VBox> <mx:DataGrid
id="dgAppleSales" > <mx:columns> <mx:Array> <mx:DataGridColumn
headerText="Shopper" columnName="label" /> <mx:DataGridColumn
headerText="Apples Purchased" columnName="qty" /> </mx:Array> </mx:columns> </mx:DataGrid> </mx:HBox> </mx:Application> From:
[email protected] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] I tried what you said and what I thought was the Array.sort
command but I can not get it to work. What I am trying to do in a nutshell is
sort the array by showing the top three numbers in order on either a button or
a label next to there respective Shoppers. I looked online for info on the
Array.sort() function but I could not see a good example of it in use? <?xml version="1.0"
encoding="utf-8"?> <mx:Object>
<mx:Button label="secondshopper" /> <mx:Button label="gettopthree"
click="getorder()"/> </mx:HBox> Yahoo! Groups Links
|
- RE: [flexcoders] Is there an easy way to do this Tracy Spratt
- RE: [flexcoders] Is there an easy way to do this Tracy Spratt

