Home Tutorials Forums Articles Blogs Movies Library Employment Press

 ActionScript.org Forums sorting multidimensional numeric array in MX
 Register FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

 06-27-2005, 05:25 AM #1 calculus Registered User   Join Date: Jun 2005 Location: New York Posts: 9 Array: how do I sort multidimensional numeric array in MX? I need some help on how to sort an array with nested arrays of matched numbers: one nested array holds x-coordinates and the other nested array holds y-coordinates. The position of each x,y pair is matched, so if I use a typical numerical sorting function, I succeed only in sorting one array or the other, and I undo the relationship. I describe my arrays below with example x,y coords, and although I may be heading in the wrong direction, I included the function that I know works to sort either one or the other array: [as] mySort = function(a,b) { return a-b; } var x= new Array(12,21,-13,48,33); var y= new Array(6, -99, 7, -2, -2); var xy = new Array(x,y) xy.sort(mySort); //output: -13,12,21,33,48,6,-99,7,-2,-2; //(only first nested array of xy sorts, so nested arrays lose their relationship) I need to output: -13,12,21,33,48,7,6,-99,-2,-2 /[as] The arrays don't have to be nested. I would be happy to be able to sort the x array and have the y array be sorted by the x array. Last edited by calculus; 06-27-2005 at 05:36 AM.
 06-27-2005, 07:31 AM #2 Xeef Off-Line     Join Date: Aug 2004 Location: Ibiza/Spain language :Hungarian/German/ abit English Posts: 6,539 hi and welcome to As.Org ActionScript Code: ```XY = [{x:12, y:6}, {x:21, y:-99}, {x:-13, y:7}, {x:48, y:-2}, {x:33, y:-2}]; for (a=0; ahttp://www.actionscript.org/forums/s...86&postcount=8
 06-27-2005, 03:51 PM #3 calculus Registered User   Join Date: Jun 2005 Location: New York Posts: 9 Arrays to nested arrays problem Thanks, Xeef I appreciate your help - having the nested array in that style did the trick! Now I'm flummoxed as to how to convert my two simple arrays into the nested style that your solution starts with: XY = [{x:12, y:6}, etc.] I tried several ways to construct the nested array style you used, and I feel I am close with the following, but no cigar: ActionScript Code: ```v = (12,21,-13,48,33); w = (6,-99,7,-2,-2); VW = [{}]; for (a=0; a

 Thread Tools Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is Off HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home ActionScript Forums Group     ActionScript 3.0     ActionScript 2.0     ActionScript 1.0 (and below)     Simple Stuff (Newbies) Flash General Questions     Flash 10 General Questions     Flash 9 General Questions     Flash 8 General Questions     Other Flash General Questions Flex     Flex 2, 3 & 4     Flex 1 Extensions and Plugins     Components     JSFL - Extending Flash Desktop, Mobile and non-browser Environments     AIR (Apollo)     FlashLite / Portable Devices Development     Projectors and CDs Supporting Technologies     HTML and JavaScript     haXe     Server-Side Scripting     Flash Remoting     Flash Media Server General     Best Practices     Gaming and Game Development     Animation and Effects     Flashants Support Forum Community Boards     General Chat     Just for Kicks Challenges     Detention Flash In Action     Site Check     Cool Sites     Widgets Decommissioned     Projects and Positions CMS Forums     Announcements Board     Content Postings / Updates     Product Review Requests     CMS Technical Questions     Process Questions     Collaboration & Suggested Articles

All times are GMT. The time now is 07:08 AM.

///