RE: [flexcoders] Is there an easy way to do this
Here is an example app: Tracy ?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 labelShopper1/label qty5/qty /mx:Object mx:Object labelShopper2/label qty7/qty /mx:Object mx:Object labelShopper3/label qty0/qty /mx:Object mx:Object labelShopper4/label qty4/qty /mx:Object mx:Object labelShopper5/label qty1/qty /mx:Object mx:Object labelShopper6/label qty0/qty /mx:Object mx:Object labelShopper7/label qty0/qty /mx:Object mx:Object labelShopper8/label qty0/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: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Wednesday, May 18, 2005 9:29 PM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] Is there an easy way to do this 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:Application xmlns:mx=http://www.macromedia.com/2003/mxml mx:Array id=apples mx:Object labelShopper1/label Number5/Number /mx:Object mx:Object labelShopper2/label Number7/Number /mx:Object mx:Object labelShopper3/label Number0/Number /mx:Object mx:Object labelShopper4/label Number4/Number /mx:Object mx:Object labelShopper5/label Number1/Number /mx:Object mx:Object labelShopper6/label Number0/Number /mx:Object mx:Object labelShopper7/label Number0/Number /mx:Object mx:Object labelShopper8/label Number0/Number /mx:Object /mx:Array mx:Script ![CDATA[ public function getorder():Void { Array.apples.sort(label,Number) firstplaceshopper.label=apples[0].label mostapples.label=apples[0].Number secondplaceshopper.label=apples[1].label secondmostapples.label=apples[1].Number thirdplaceshopper.label=apples[2].label thirdmostapples.label=apples[2].Number } ]] /mx:Script mx:HBox id=whohasthemost visible=true mx:Button label=firstshopper / mx:Button width=100 id=firstplaceshopper / mx:Button label=Number of apples / mx:Button width=30 id=mostapples/ mx:Button label=secondshopper / mx:Button width=100 id=secondplaceshopper / mx:Button label=Number of apples / mx:Button width=30 id=secondmostapples/ mx:Button label=thirdshopper / mx:Button width=100 id=thirdplaceshopper / mx:Button label=Number of apples / mx:Button width=30 id=thirdmostapples/ mx:Button label=gettopthree click=getorder()/ /mx:HBox /mx:Application 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 the Yahoo! Terms of Service.
RE: [flexcoders] Is there an easy way to do this
Ahh, sortOn works with a property name. I didn't know that. Pretty handy Tracy -Original Message- From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Manish Jethani Sent: Thursday, May 19, 2005 3:36 AM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] Is there an easy way to do this On 5/19/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: [...] mx:Array id=apples mx:Object labelShopper1/label Number5/Number /mx:Object mx:Object labelShopper2/label Number7/Number /mx:Object mx:Object labelShopper3/label Number0/Number /mx:Object [...] You want to sort by the number of apples. apples.sortOn(Number); apples.sort().reverse(); // that was ascending I'm pretty sure there's a way to directly sort descending, ... Yahoo! Groups Links 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/
Re: [flexcoders] Is there an easy way to do this
On 5/19/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: [...] mx:Array id=apples mx:Object labelShopper1/label Number5/Number /mx:Object mx:Object labelShopper2/label Number7/Number /mx:Object mx:Object labelShopper3/label Number0/Number /mx:Object [...] You want to sort by the number of apples. apples.sortOn(Number); apples.sort().reverse(); // that was ascending I'm pretty sure there's a way to directly sort descending, ... 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/
[flexcoders] Is there an easy way to do this
I know I probably can figure out how to do this eventually. My problem with my programming skills is my programs tend to be bigger and more filled with code than they need to be. So I am trying to learn to get the job done with less code. Here is one thing I trying to do and its been making me crazy, is lets say you have eight people ok and they each have a certain number of apples in there bag.with nobody having the same amount. So lets say I want to get the top three people who have the most apples listed respectively alongside the person who has the apples. Is there an easy way to do this? I mean I have thought about making several arrays and doing loops but for some reason I feel there is a much easier way. Any suggestions? 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 the Yahoo! Terms of Service.
RE: [flexcoders] Is there an easy way to do this
Use a single array, and look into Array.sort(). It allows you to define and pass function that will sort the array however you want. Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Wednesday, May 18, 2005 11:59 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] Is there an easy way to do this I know I probably can figure out how to do this eventually. My problem with my programming skills is my programs tend to be bigger and more filled with code than they need to be. So I am trying to learn to get the job done with less code. Here is one thing I trying to do and its been making me crazy, is lets say you have eight people ok and they each have a certain number of apples in there bag.with nobody having the same amount. So lets say I want to get the top three people who have the most apples listed respectively alongside the person who has the apples. Is there an easy way to do this? I mean I have thought about making several arrays and doing loops but for some reason I feel there is a much easier way. Any suggestions? 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 the Yahoo! Terms of Service.
Re: [flexcoders] Is there an easy way to do this
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:Application xmlns:mx="http://www.macromedia.com/2003/mxml"mx:Array id="apples"mx:ObjectlabelShopper1/labelNumber5/Number/mx:Objectmx:ObjectlabelShopper2/labelNumber7/Number/mx:Objectmx:ObjectlabelShopper3/labelNumber0/Number/mx:Objectmx:ObjectlabelShopper4/labelNumber4/Number/mx:Objectmx:ObjectlabelShopper5/labelNumber1/Number/mx:Objectmx:ObjectlabelShopper6/labelNumber0/Number/mx:Object mx:ObjectlabelShopper7/labelNumber0/Number/mx:Objectmx:ObjectlabelShopper8/labelNumber0/Number/mx:Object /mx:Arraymx:Script![CDATA[public function getorder():Void{Array.apples.sort(label,Number)firstplaceshopper.label=apples[0].labelmostapples.label=apples[0].Numbersecondplaceshopper.label=apples[1].labelsecondmostapples.label=apples[1].Numberthirdplaceshopper.label=apples[2].labelthirdmostapples.label=apples[2].Number}]]/mx:Scriptmx:HBox id="whohasthemost" visible="true" mx:Button label="firstshopper" /mx:Button width="100" id="firstplaceshopper" /mx:Button label="Number of apples" /mx:Button width="30" id="mostapples"/ mx:Button label="secondshopper" /mx:Button width="100" id="secondplaceshopper" /mx:Button label="Number of apples" /mx:Button width="30" id="secondmostapples"/mx:Button label="thirdshopper" /mx:Button width="100" id="thirdplaceshopper" /mx:Button label="Number of apples" /mx:Button width="30" id="thirdmostapples"/ mx:Button label="gettopthree" click="getorder()"/ /mx:HBox/mx:Application 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 the Yahoo! Terms of Service.