Array.sort
OK, so I tried making some numbers sorting in an array, as you know it didn't work, so I made this:
function numberSort(a, b) {
return b>a;
}
organ.sort(numberSort);
of course it works, but!
my problem is that I have in each cell in the array two things: name, score.
I want to sort it according to the score.
now if I was using sortOn, I could do sortOn("score");
but then i get back to the first problem -> it doesn't sort good.
so, how can I sort according to the score And sort the numbers like it should be.
Ultrashock Forums > Flash > ActionScript
Posted on: 2003-04-18
View Complete Forum Thread with Replies
Sponsored Links:
Array.sort - Can Someone Help Me Through It?
hello, (trying to make arrayes work....)
I have an Array that symbols a Tree menu
menuItems = new Array(1, 1.1, 1.11, 1.12, 1.2, 1.21, 1.22, 1.3, 1.31, 1.32, 1.33, 2, 2.1, 2.11, 2.12, 2.2, 2.21, 2.22, 2.3, 2.31, 2.32, 2.33, 3, 3.1, 3.11, 3.12, 3.2, 3.21, 3.22, 3.3, 3.31, 3.32, 3.33, ...);
now I have to extract those array items according to their level.
I tried to do this by the string length
for (i=0; i<_root.menuItems.length-1; i++) {
if (_root.menuItems[i].length==1) {
duplicateMovieClip (this.menuItem0, "menuItem"+(i), i);
}
}
but no luck....
I think that Array.sort have something to do with it (?)
or if anybody knows of a another good way to sort those Array items by their level:
12345
1.1, 1.2
1.11,1.12, 1.21
2.1 2.2
Sorry for the long story...hope the problem is clear.
View Replies !
View Related
Array.sort() - How To Do It Right?
thank you for checking,
i'm trying to sort an array with its .sort()-method.
what i have is:
39,58,18,-40,-19,-59
after sorting it looks like this:
-19,-40,-59,18,39,58
now, that ain't right!
but i want it right! how to?
*marc
View Replies !
View Related
Would An Array Sort This Out?
hi, I got a php script yesterday (a chat script). A var called userlist lists all the names into the timeline:
eg.
userlist = "joe blogs,tiger woods,yugo Nakamura";
now.. what i need is these names set into other vars like so:
ItemData1 = "joe blogs";
ItemData2 = "john smith";
ItemData3 = "tiger woods";
I think an array would sort this out, but ive only just started learning about them so im not shure how to do it
could you help me out? i dont think it should be too hard to do.
View Replies !
View Related
Array.sort Bug?
Hi Guys,
i'm hoping someone can shed some light on a problem i've having with the array.sort() function using a custom sorting routine....
I'm developing a world cup games results planner, and there's no problem in reading in the match results etc. but when i come to sort a group table, a previewed swf gives the opposite of a published swf in a web page!!
Here's the sorting rules for the teams in a group:
1.most points
2.better goal difference
3.more goals scored
4.result between the 2 teams
i've littered the sort function with trace statements so i can try and see what's going on...
here's the output from the swf in preview mode:
Code:
true
R:0 t1:0-4 t2:1-1
R:1 t1:2-1 t2:3-2
R:2 t1:0-1 t2:2-3
R:3 t1:3-2 t2:1-1
R:4 t1:3-1 t2:0-1
R:5 t1:1-2 t2:2-2
sorting:3 0:b points> a
sorting:3 0:b points> a
sorting:1 0:a points> b
sorting:1 0:a points> b
sorting:2 0:a == b
sorting:2 0:a == b
sorting:2 3:a points> b
sorting:3 3:a == b
sort done
and here's the output from the published swf in a web page:
Code:
true
R:0 t1:0-4 t2:1-1
R:1 t1:2-1 t2:3-2
R:2 t1:0-1 t2:2-3
R:3 t1:3-2 t2:1-1
R:4 t1:3-1 t2:0-1
R:5 t1:1-2 t2:2-2
sorting:0 3:a points> b
sorting:0 2:a == b
sorting:0 2:a == b
sorting:0 1:b points> a
sorting:2 1:b points> a
sorting:2 1:b points> a
sort done
The output from both should be the same (as there's no change in any code or variables in the 2 versions) yet it seems to be reversing the swap in the published swf...
Anyone have the foggiest idea what might be going on?
cheers,
Andy
View Replies !
View Related
Sort Array?
Fixed it - see below:
var attachCnt:Number = 0;
var attachMCsArray:Array = new Array();
this.onMouseUp = function() {
if (_ymouse<500) {
attachMovie("mc_square", "mc_square_"+attachCnt, attachCnt);
this["mc_square_"+attachCnt]._x = _xmouse;
this["mc_square_"+attachCnt]._y = _ymouse;
this.attachMCsArray.push(this["mc_square_"+attachCnt]);
attachCnt++;
}
};
function sortByYCoor(clip1, clip2) {
clip1y = clip1._y;
clip2y = clip2._y;
return clip1y-clip2y;
}
function setAttachedMCsDepth() {
for (i=0; i<=attachMCsArray.length-1; i++) {
eval(attachMCsArray[i]).swapDepths(i+100);
}
}
this.btn_check.onRelease = function() {
attachMCsArray.sort(sortByYCoor);
setAttachedMCsDepth();
};
================================================== =======
Hey guys,
Can anyone see why this code isn't working? [FLA attached] I'm trying to sort an array based on the Xpos of the entry.
Running Flash 8 pro, exporting to AS2 FP v7
Thanks in advance
Ol
var attachCnt:Number = 0;
attachMCsArray = new Array();
this.onMouseUp = function() {
if (_ymouse<500) {
attachMovie("mc_square", "mc_square_"+attachCnt, attachCnt);
this["mc_square_"+attachCnt]._x = _xmouse;
this["mc_square_"+attachCnt]._y = _ymouse;
//this["mc_square_"+attachCnt].onRollOver = function() {
//trace(this._name);
//trace(this._y)
//};
this.attachMCsArray.push("mc_square_"+attachCnt);
attachCnt++;
}
};
function sortByYCoor(clip1, clip2) {
clip1y = clip1._y;
clip2y = clip2._y;
trace(clip1._y);
return clip1y-clip2y;
}
this.btn_check.onRelease = function() {
attachMCsArray.sort(sortByYCoor);
trace(attachMCsArray);
};
View Replies !
View Related
Sort An Array?
Would like to sort the following array to display like so:
6,7,8,9,10,1,2,3,4,5
I have coded the following:
Code:
var arr:Array = new Array(1,2,3,4,5,6,7,8,9,10);
var half = Math.round(arr.length/2);
var spliced:Array = arr.splice(half, half);
arr.splice(0, 0, spliced);
trace(arr);
Is there a better more efficient way to do this?
View Replies !
View Related
Array Sort
hi,
I want to sort this array of 55 numbers
when i use the code
Code:
//original = new Array();
original = [0.01, 0.01, 0.75, 1.00, 1.90, 0.35, 0.02, 0.35, 0.01, 1.00, 1.94, 5.00, 0.06, 0.40, 0.79, 0.01, 2.00, 7.00, 0.15, 0.41, 0.80, 1.10, 0.01, 8.55, 0.08, 0.50, 0.80, 1.52, 2.32, 21.00, 0.08, 0.50, 0.80, 1.25, 2.50, 0.12, 0.52, 0.85, 1.50, 2.60, 0.10, 0.60, 1.00, 1.75, 3.29, 0.22, 0.70, 1.00, 1.80, 2.50, 0.15, 0.72, 1.00, 1.85, 3.80];
sorted = new Array();
sorted = original.sort();
trace(sorted);
var i;
for (i=0; i<55; i++) {
result.addItem(sorted[i]);
}
the result i get is not properly sorted ..to be more precise in the sorted output iam getting 21.00 right after 2.60 where as it shud come only in the end...
I have 2 doubts
1) are the array elements considered as strings?
2) Can we declare an array of type float??
Can anybody help??
_____________________________
regards,
Sandhya
Code:
View Replies !
View Related
Array And Sort()
I can't make array.sort() to work. What i need to do - i have a couple of numbers - lets say 4 in an array like this
c[1]=10
c[2]=5
c[3]=13
c[4]=3
then i need to sort them and somehow "remember" where they were before.
The result should be
3,5,10,13
but i need also an index list of how it was sorted like this:
4,2,1,3 (means c[4] is lowest - c[2] is next etc etc)
Hope someone can help me on this
View Replies !
View Related
Array Sort
hi,
I want to sort this array of 55 numbers
when i use the code
Code:
//original = new Array();
original = [0.01, 0.01, 0.75, 1.00, 1.90, 0.35, 0.02, 0.35, 0.01, 1.00, 1.94, 5.00, 0.06, 0.40, 0.79, 0.01, 2.00, 7.00, 0.15, 0.41, 0.80, 1.10, 0.01, 8.55, 0.08, 0.50, 0.80, 1.52, 2.32, 21.00, 0.08, 0.50, 0.80, 1.25, 2.50, 0.12, 0.52, 0.85, 1.50, 2.60, 0.10, 0.60, 1.00, 1.75, 3.29, 0.22, 0.70, 1.00, 1.80, 2.50, 0.15, 0.72, 1.00, 1.85, 3.80];
sorted = new Array();
sorted = original.sort();
trace(sorted);
var i;
for (i=0; i<55; i++) {
result.addItem(sorted[i]);
}
the result i get is not properly sorted ..to be more precise in the sorted output iam getting 21.00 right after 2.60 where as it shud come only in the end...
I have 2 doubts
1) are the array elements considered as strings?
2) Can we declare an array of type float??
Can anybody help??
View Replies !
View Related
Array Sort
hi,
i have this array when traced in flash looking like this;
Quote:
ID - NAME - BOO - BOO - SUB ID
---------------------------------
1,NO,false,false,0
2,OM BRASSWIND,true,false,1
3,PROGRAM,true,false,1
4,EN,false,false,0
5,ABOUT BRASSWIND,true,false,4
6,PROGRAM,false,true,4
7,Saturday,false,true,6
8,Lřrdag,false,true,3
---------------------------------
What i'm trying to do is to sort after the SUB ID so the parent section comes at top and the childs follows underneath.
Any ideas of how this is done?
Next i want to attach different moviclips to the parent, child and childs child section.
great if someone could help..
tanx.
View Replies !
View Related
Array - Sort()
this is something i really want help with cause i don't really understand any of the 'Array' functions. any way, i have made homing missiles in flash, but i want to make them 'pick' their targets acording to distance from the missile to the target. here is what im currently using:
function findTarget(obj) {
for (i=0; i<Targets.length; i++) {
xdif = obj._x-Targets[i]._x;
ydif = obj._y-Targets[i]._y;
targetDis[i] = Math.sqrt(xdif*xdif+ydif*ydif);
}
targetDis.sort();
findRot(obj, Targets[eval(targetDis[0])]._x, Targets[eval(targetDis[0])]._y);
}
this function would be called from inside the missile like this: findTarget(this)
what exactaly does sort() and what should i use for my homing missiles?
thanx Heaps
Dom
View Replies !
View Related
Sort In An Array
is the sort method the only function that can reposition elements in an array, i have an array with four elements, depending on the situation, i would like to grab one element and move it either to the top or bottom of the array
View Replies !
View Related
Array Sort
hi,
I want to sort this array of 55 numbers
when i use the code
Code:
//original = new Array();
original = [0.01, 0.01, 0.75, 1.00, 1.90, 0.35, 0.02, 0.35, 0.01, 1.00, 1.94, 5.00, 0.06, 0.40, 0.79, 0.01, 2.00, 7.00, 0.15, 0.41, 0.80, 1.10, 0.01, 8.55, 0.08, 0.50, 0.80, 1.52, 2.32, 21.00, 0.08, 0.50, 0.80, 1.25, 2.50, 0.12, 0.52, 0.85, 1.50, 2.60, 0.10, 0.60, 1.00, 1.75, 3.29, 0.22, 0.70, 1.00, 1.80, 2.50, 0.15, 0.72, 1.00, 1.85, 3.80];
sorted = new Array();
sorted = original.sort();
trace(sorted);
var i;
for (i=0; i<55; i++) {
result.addItem(sorted[i]);
}
the result i get is not properly sorted ..to be more precise in the sorted output iam getting 21.00 right after 2.60 where as it shud come only in the end...
I have 2 doubts
1) are the array elements considered as strings?
2) Can we declare an array of type float??
Can anybody help??
View Replies !
View Related
Array.sort ....any Ideas?
OK, this should be a simple problem for anyone who's dealt with it...
looking for a way to sort an array accurately. Items have up to 7 digits and need to be sorted to all 7 digits, no decimal places.
As of now, using the built in sort, I'm getting accuracy to 4 digits. I have played with a lot of different sorting algorhythms (some simple, some more complicated), but havent had any luck with sorting the first element of arrays in place. To give an idea of what I'm doing-
I'm using a multidimensional array- let's say with two hundred two item arrays- I need to sort the two item arrays by the value of their first item- perfect for the built in sort function. no problem with four digit values, no problem with letters.
Anyone seen this before?
Thanks, PeterG
View Replies !
View Related
Random Sort Of An Array
here's the problem:
i have a bit of actionScript that generates an array of filenames. basically it looks like this :
loadOrder= ["slideshow/soul1.swf", "slideshow/soul2.swf","slideshow/fashion1.swf","slideshow/fashion2.swf", etc];
there are 12 .swf files in six categories, for a total of 72 files.
now, i want to randomly determine the load order of these files, each time the user accesses the parent .swf. currently, i have the file randomly choosing one of the 72 files, but is there a way to either:
1. randomly sort the array each time so that i can just access in order from index 0 to 71?
or
2. randomly select a number from 0 to 71, but not repeat a number until all 72 possible files have been chosen?
i've tried a few different solutions, but they all seemed to be more complex than should be necessary. am i over thinking this problem, or is it a tricky one?
thanks in advance.
d.
View Replies !
View Related
How Does One Sort An Array In ABC Order
Hey peeps wussup? Okay now here's basically the problem I am trying to work out either using Java or Actionscript. I want to sort a list of words in ABC order and also check how many times each word occurs in the list. Here is an example below. Let's say that I have a text file that I bring into the flash movie by using a constructor and I have each word sorted into an array.
myArray = ["this", "happens", "to", "be", "only", "a", "test", "this", "time"];
Alright, now what I want to do is create a function here that will result in the following output:
a 1
be 1
happens 1
only 1
test 1
this 2
time 1
to 1
The final result is that each word is placed on a new line in ABC order and the number next to each word specifies how many times the word was found in the array. Okay well look I know it's sort of alot, but the reason I need to understand how to do this is because I've created a jukebox for my new site and I want to be able to sort everything alphabetically. Check it out below and let me know how you think it works. Preciate the help and feedback.
Beta Testing Phase: http://www.2hitek.com/v2
View Replies !
View Related
Array Sort By Value - Easy?
hi there,
I pulling data from a DB split it into to array and now I would like to sort it depending on a specific value.
myArr[0] = ["nameA",0,"mail"]
myArr[1] = ["nameB",2,"mail"]
myArr[2] = ["nameC",1,"mail"]
myArr[3] = ["nameD1",1,"mail"]
myArr[4] = ["nameE",0,"mail"]
myArr[5] = ["nameF",2,"mail"]
I would like to sort the array depending on the second value.
All values of '1' should go first. Followed by all values of '0' and then all values of '2'.
To make it look like this
myArr[0] = ["nameC",1,"mail"]
myArr[1] = ["nameD",1,"mail"]
myArr[2] = ["nameA",0,"mail"]
myArr[3] = ["nameE",0,"mail"]
myArr[4] = ["nameB",2,"mail"]
myArr[5] = ["nameF",2,"mail"]
Am I making myself understandable?
Regards
//PODEN
View Replies !
View Related
How Can I Sort An Array With Object In?
I want to sort an array that contains object references.
I want to sort on one of the values held by the objects.
I have the following sample code, say:
code:
abc = new Array();
abc[0] = new Object();
abc[0].anotherObj = new Object();
abc[0].anotherObj.myNumber = 21;
abc[1] = new Object();
abc[1].anotherObj = new Object();
abc[1].anotherObj.myNumber = 11;
abc[2] = new Object();
abc[2].anotherObj = new Object();
abc[2].anotherObj.myNumber = 2;
abc[3] = new Object();
abc[3].anotherObj = new Object();
abc[3].anotherObj.myNumber = 3;
abc.sortOn("anotherObj.myNumber", Array.NUMERIC);
trace(abc[0].anotherObj.myNumber);
trace(abc[1].anotherObj.myNumber);
In the above code... I want to sort on anotherObj.myNumber.
The above doesn't work.
I wasn't sure what I should put for anotherObj.myNumber??
Any help would be appreciated.
Thanks.
OM
View Replies !
View Related
[F8] Randomly Sort An Array
i was wondering if there was an easy way to put the numbers in an array any length in a random order in an array.
so like {0, 1, 2, 3, 4} could be {5, 3, 1, 2, 4} or {4, 2, 5, 1, 3}
just randomly anywhere :P
View Replies !
View Related
[F8] Array Sort() Problem
Hello,
Here's my code:
Code:
trace("+++"+cropprofit);
cropprofitsortedindx = cropprofit.sort(Array.RETURNINDEXEDARRAY | Array.DESCENDING);
trace("+++"+cropprofitsortedindx);
Here is an example output from that code:
code: +++1,7,-1.5,1,-5
+++1,3,0,4,2
This is not correct. The second line should read +++1,3,0,2,4, as -1.5 > -5. Here's another example:
code: +++5,5,-3.5,-1,-5
+++1,0,4,2,3
The same problem exists as before; the second line should read +++1,0,3,2,4. Is there something I'm doing wrong here? Or is this an issue with the actual function (Array.sort)? I'm stuck
View Replies !
View Related
[AS3]How Do I Sort A Object Array?
I have array of objects, and the objects have their properties like subject, text, date, etc. Now i want to sort the array based on the date property of the objects, any ideas on how to do this?
Also the date is being taken from the "time()" function in php and is formatted in php in the form dd/mm/yyyy , before getting into flash! Is there any easy way to format the date in flash like php?
View Replies !
View Related
Constructing ([a,b],[c,d]) Sort Of Array
I'm trying to constuct an array dynamically like
someArray = new Array([1,2],[2,3]);
Function starts like:
var someArray:Array = new Array();
for (i=1; i<20; i++) {
then none of the following worked:
someArray.push("["+i+","+(i+1)"]");
someArray.push([i][i+1]);
someArray.push([+i+(i+1)+]);
Since I want to construct the array actually with numbers, I shouldn't use quotes, but in fact what should be the way to achieve such thing?
Any help is more than appreciated.
View Replies !
View Related
Array Sort Problem
Hi Group
I am trying to write a scoring mechanism for a game show
I am new to actionscript and I am trying to sort the array below in descending order by the score values and get it to deal with negative values as well.
var winOrder:Array = new Array(new Array(score01,name01), new Array(score02,name02),new Array(score03,name03),new Array(score04,name04),new Array(score05,name05));
winOrder.sort();
// setup vars for winning order
postion05 = (winOrder[0][0]);
postion05Name = (winOrder[0][1]);
postion04 = (winOrder[1][0]);
postion04Name = (winOrder[1][1]);
postion03 = (winOrder[2][0]);
postion03Name = (winOrder[2][1]);
postion02 = (winOrder[3][0]);
postion02Name = (winOrder[3][1]);
postion01 = (winOrder[4][0]);
postion01Name = (winOrder[4][1]);
it works but does not sort correctley with negative numbers
Any help would be grately appreciated.
Kind regards
Aaron Denson
aaron.denson@onetel.net
View Replies !
View Related
Alpha Sort Array?
suppose I have an array like this:
PHP Code:
array [0] = "John";
array [1] = "Adam";
array [2] = "Bill";
I want to be able to display the array values alphabetically in ASCENDING OR DESCENDING order.
right now I have to constantly sendAndLoadVars to PHP so it can generate and XML string using this command.
PHP Code:
SELECT * FROM mytable ORDER BY fname ASC
If I can find a way to load the variables into an array and have the array sort it - it will mean my server only has to process the data to the movie once.
thanks!
View Replies !
View Related
Copying An Array, And Sort();
hi! long time no see
im trying to load an array of data, make a copy of it, sort the array, and then trace the two arrays... the problem is that the copyed array gets sorted too... I've found a way to solve that, but I was just wondering if anyone can explain me this behavior...
here is the code:
ActionScript Code:
//pics is the original array.
pics2 = pics;
//pics2 = new Array (pics.join (",")); solved it with this line...
trace (pics);
trace (pics2);
trace (".............................sort.................................");
pics2.sort (sortRand);//sortRand is to generate a random order, and i got the function here is as.org
trace (pics);
trace (pics2);
... not a big problem really, but would help to know.
thanksss!
View Replies !
View Related
Tricky Array Sort
I have an array with string values of 1,2,3,4a,5,6,4b,10,7
I would like to sort the array into 1,2,3,4a,4b,5,6,7,10
Would this be possible? I can't seem to do this with the standard sorting
methods in flash.
This needs to be targeted to flash player 7.
Thanks for any pointers.
View Replies !
View Related
How Can I Sort An Array With Objects In?
I want to sort an array that contains object references.
I want to sort on one of the values held by the objects.
I have the following sample code, say:
ActionScript Code:
ActionScript:abc = new Array(); abc[0] = new Object(); abc[0].anotherObj = new Object(); abc[0].anotherObj.myNumber = 21; abc[1] = new Object(); abc[1].anotherObj = new Object(); abc[1].anotherObj.myNumber = 11; abc[2] = new Object(); abc[2].anotherObj = new Object(); abc[2].anotherObj.myNumber = 2; abc[3] = new Object(); abc[3].anotherObj = new Object(); abc[3].anotherObj.myNumber = 3; abc.sortOn("anotherObj.myNumber", Array.NUMERIC); trace(abc[0].anotherObj.myNumber); trace(abc[1].anotherObj.myNumber);
In the above code... I want to sort on anotherObj.myNumber.
The above doesn't work.
I wasn't sure what I should put for anotherObj.myNumber??
Any help would be appreciated.
Thanks.
OM
View Replies !
View Related
Possible To Sort Objects In Array?
Hi guys, help me please!
I would like to make an array with some objects, let's say something like this:
Code:
var berry = new Object;
berry.color = "purple";
berry.taste = "good";
var orange = new Object;
orange.color = "orange";
orange.taste = "acid";
var strawberry = new Object;
strawberry.color = "red";
strawberry.taste = "sweet";
var fruit_array:Array = new Array(berry, orange, strawberry);
for(var i=0; i<3; i++){
trace(fruit_array[i].color +" - "+ fruit_array[i].taste);
}
And now I would to trace the whole array, but sorted by color of the fruit or taste. Is it possible? If yes, how? Thanks a bunch for ideas, opinions, etc.
Poco
View Replies !
View Related
Xml Sort Array Issue
Ive been trying to sort an xml array based on a date , and i cant get it to work ive tried a few things at this point
Code:
/////////////////////////////////////////////////////////////////////////
function order(a, b):Number {
trace(a.childNodes.length)
var name1:Number = a;
var name2:Number = b;
trace(name1+", "+name2);
if (name1<name2) {
return -1;
} else if (name1>name2) {
return 1;
} else {
return 0;
}
}
///////////////////////////////////////////////////////////////////////////
El.onLoad = function(success:Boolean) {
var childs:XMLNode = this.firstChild;
var childTotal:Number = childs.childNodes.length;
var sh:Array = this.firstChild.childNodes;
_root.sh = sh;
dropframe = [];
for (i=0; i<sh.length; i++) {
dropframe.push(childs.childNodes[i].childNodes[8].firstChild);
}
dropframe.sort();
_global.shh = childTotal;
for (i=0; i<sh.length; i++) {
sh.sort(dropframe);
trace(dropframe[i]);
var s:Array = sh[i].childNodes;
ids = sh[i].firstChild;
and the xml
Code:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<newshows>
<showd>
<id>62</id>
<preview1>Apr 18, 2007 21:30</preview1>
<preview2>All s Place</preview2>
<preview3>West Hollywood, CA</preview3>
<detail1>Apr 18th 2007 @ 8:00pm</detail1>
<WEB>http://thegypsylounge.com/</WEB>
<detail2>Bob's Place</detail2>
<detail3>9081 Santa Monica Blvd %3Cbr%3EWest Hollywood,Ca.90069 %3Cbr%3E(714) 555-2222%3Cbr%3E%3Cbr%3E %3Ca%20href=%22http://yahoo.maps.com%22%3E[Map]%3C/a%3E%3Cbr%3EInfo: $5.00%3Cbr%3E%3Cb%3E%3Cbr%3EComments:%3C/b%3E%3Cbr%3Ehttp://www.oberlin.edu/students/links-life/sco.html%3Cbr%3E</detail3>
<dates>2004,4,18</dates>
</showd>
<showd>
<id>69</id>
<preview1>May 18, 2007 21:30</preview1>
<preview2>All Ages @ Joes Place</preview2>
<preview3>East Hollywood, CA</preview3>
<detail1>May 18th 2007 @ 8:00pm</detail1>
<WEB>http://thegypsylounge.com/</WEB>
<detail2>Bob's Pe</detail2>
<detail3>555 Santa Monica Blvd %3Cbr%3E Hollywood,Ca.90069 (714) 555-2222</detail3>
<dates>2004,5,18</dates>
</showd>
</newshows>
View Replies !
View Related
Array Sort Problem
hello, i'v got this sorting problem with arrays
Code:
var ar1:Array = new Array("345","300","450","70","200","100","125");
var ar2:Array = ar1;
trace(ar1); // returns 345,300,450,70,200,100,125
ar2.sort(Array.NUMERIC);
trace(ar1); // returns 70,100,125,200,300,345,450
trace(ar2); // returns 70,100,125,200,300,345,450
why it sorts both of arrays?
i need to sort only ar2? how it could be done?
View Replies !
View Related
How Can I Sort An Array With Objects In?
I want to sort an array that contains object references.
I want to sort on one of the values held by the objects.
I have the following sample code, say:
ActionScript Code:
ActionScript:abc = new Array(); abc[0] = new Object(); abc[0].anotherObj = new Object(); abc[0].anotherObj.myNumber = 21; abc[1] = new Object(); abc[1].anotherObj = new Object(); abc[1].anotherObj.myNumber = 11; abc[2] = new Object(); abc[2].anotherObj = new Object(); abc[2].anotherObj.myNumber = 2; abc[3] = new Object(); abc[3].anotherObj = new Object(); abc[3].anotherObj.myNumber = 3; abc.sortOn("anotherObj.myNumber", Array.NUMERIC); trace(abc[0].anotherObj.myNumber); trace(abc[1].anotherObj.myNumber);
In the above code... I want to sort on anotherObj.myNumber.
The above doesn't work.
I wasn't sure what I should put for anotherObj.myNumber??
Any help would be appreciated.
Thanks.
OM
View Replies !
View Related
How Can I Sort An Array With Objects In?
I want to sort an array that contains object references.
I want to sort on one of the values held by the objects.
I have the following sample code, say:
ActionScript Code:
ActionScript:abc = new Array();
abc[0] = new Object();
abc[0].anotherObj = new Object();
abc[0].anotherObj.myNumber = 21;
abc[1] = new Object();
abc[1].anotherObj = new Object();
abc[1].anotherObj.myNumber = 11;
abc[2] = new Object();
abc[2].anotherObj = new Object();
abc[2].anotherObj.myNumber = 2;
abc[3] = new Object();
abc[3].anotherObj = new Object();
abc[3].anotherObj.myNumber = 3;
abc.sortOn("anotherObj.myNumber", Array.NUMERIC);
trace(abc[0].anotherObj.myNumber);
trace(abc[1].anotherObj.myNumber);
In the above code... I want to sort on anotherObj.myNumber.
The above doesn't work.
I wasn't sure what I should put for anotherObj.myNumber??
Any help would be appreciated.
Thanks.
OM
View Replies !
View Related
Sort Array By Length
is there an easy way of sorting an array by the length of the values within the array. e.g.
Text[0] = and
Text[1] = zero
Text[2] = it
Text[3] = action
I want it to sort it like this. The longest word first.
Text[0] = action
Text[1] = zero
Text[2] = and
Text[3] = it
Thanks
-Rob
View Replies !
View Related
Sort Array Of Numbers
I created this script to test.
Objective: I wanted to find out which variable had the highest value and return the name of that variable.
Problem: The functions work BUT it treats the variable values as if it were like strings. For example if we had 3 numbers to sort... 9, 23,78
Then the sorted result would be 9,78,23.
The problem is that it reads the numbers beginning with the first digit. So instead of 78,23,9 like what I expect the array.sort() sees 9,7,2 the first digits of the number. Only when the numbers have identitcal first digits does it go on to the second digits to sort. ie 34,38,35, 7 would sort to 7,38,35,34
Is there an easy answer to solve this ?
(or do I have to write an extra function to code around this ? )
Code:
function generatenum(){
a=Math.round(Math.random()*30);
b=Math.round(Math.random()*50);
c=Math.round(Math.random()*50);
d=Math.round(Math.random()*20);
e=Math.round(Math.random()*100);
testarray1=new Array(a,b,c,d,e);
}
this.onMouseDown=function(){
testarray1=testarray1.sort();
testarray1=testarray1.reverse();
switch(testarray1[0]){
case a:
winner="a";
break;
case b:
winner="b";
break;
case c:
winner="c";
break;
case d:
winner="d";
break;
case e:
winner="e";
break;
}
}
this.onMouseUp=function(){
generatenum();
}
View Replies !
View Related
Sort An Array By Word Length?
Does anyone know a simple way sort an array by word length?
So, for example if my array is...
myArray("weasel","cat","bird")
I would like the output to be...
cat, bird, weasel
I know it's easy to sort alphabetically but that's the only way that I can find to do it.
-Brad
View Replies !
View Related
Array Sort By Date Values
I'm lost. I've read in an XML file containing event dates, and need to sort the resulting array by that date field.
The XML file is presented three different ways, and I can not ensure the XML file creator will always sort it by date. Blah...
Any ideas on how to sort by date? I thought about using Date.UTC but can't quite figure out how to append a column to the array.
Thanks for any assistance!
Jeff
View Replies !
View Related
Convert Variables Into Array To Sort
I have a lot of variables , a1 a2 a3 a4 etc ( tha values are names).
I want to sort these names in alphabetical order and have them all in a textfield.
How do I convert the variables into an array that can be sorted?
I have a sorting script.........
// Sorting Order Function
lowToHigh = function (a, b) {
return a>b;
};
names.sort(lowToHigh);
.....but I have troubles converting the variables to an Array.
View Replies !
View Related
Problem : Array.sort() With Numbers
Hi.
Can someone tell me how the Numbers are sorted in ActionScript
//an exemple :
A_TEST1 = new Array(234, 89, 1, 10, 123);
A_TEST1.sort();
trace(A_TEST1);
// return : 1,10,123,234,89
That' means that ActionScript considers 10 as 1+0, and not 10.
This is a big problem.
Is anybody has a solution to avoid this problem ?
thanks.
View Replies !
View Related
Array Sort/ Size Reduction
Hi- in making an XML text "search engine" I've run into a problem which I cannot solve. No matter how much I puzzle over it I am stuck in the same rut. I really need a good hard kick to get me out.
Let me simplify:
With
code:
var aTemp=new Array();
aTemp[0]="A";
aTemp[1]="B";
aTemp[2]="C";
aTemp[3]="A";
aTemp[4]="A";
I would like to get from this another array, with values
code:
aFinal[0]="A"
aFinal[1]="B"
aFinal[2]="C"
I cannot work out how to do it though... Thanks for any hints
View Replies !
View Related
Array.sort (stings That Have Number At The End)
hi,
I have a problem with sorting an array.
I push into _name of objects and these names are like object1, object19, object23, object9.
Object9 alway take last position in array. Is it possible to sort it by increasing object numeber.
Tip: I cant substring string because i neeed whole name latter on.
thx
View Replies !
View Related
Array.sort + Class Instance
Hi basically I have an array which contains multiple instances of a particular class which contains a private var numbersLeft which is set using setter getter method.
I would like to know if I can use Array.sort or Array.sortOn to sort this array of classes - as a class is essentially an object.
But dont know how to go about it ticket_array is my array & numberLeft is getter method but dont know if this is right
var t_sorted_array:Array = new Array(ticket_array.sort(ticket_array.numberLeft, Array.NUMERIC | Array.DESCENDING));
Or does anyone know a better way
View Replies !
View Related
Sort Array Of Objects By Date
hi. i have the following code i cannot sort the array of objects by date ! is this possible ?
PHP Code:
import com.xfactorstudio.xml.xpath.*;
import mx.remoting.RecordSet;
var temp_date:Date = new Date();
trace(temp_date.getFullYear());
////////////////////////////////////////////////////////////////////// GET NEWS
var getNewsObj:XML = new XML();
getNewsObj.ignoreWhite = true;
var getNews:Object = new Object();
getNewsObj.onLoad = function(sucsess:Boolean) {
if (sucsess) {
getNews = getNewsObj;
buildNews("all");
} else {
trace("xml path error");
}
};
getNewsObj.load("xml/getNews.xml");
///////////////////////////////////////////////////////////////////////////////////////
var len:Number;
var sort_array:Array = new Array();
///////////////////////////////////////////////////////////////////////////////////////
function byDate(a, b) {
return (Number(a)>Number(b));
}
///////////////////////////////////////////////////////////////////////////////////////
function dateStringToObject(dateString) {
var date_ar = dateString.split("/");
return new Date(date_ar[2], date_ar[0]-1, date_ar[1]);
}
///////////////////////////////////////////////////////////////////////////////////////
function buildNews(param:String):Void {
var query:String;
if (param == "all") {
query = "//newsItem";
}
var result:Object = XPath.selectNodes(_root.getNews, query);
len = result.length;
for (inc=0; inc<len; inc++) {
// BUILD NEWS CORE DATA STRUCT
var temp_data:Object = new Object();
temp_data.id = XPath.selectNodes(result[inc], "./id")[0].firstChild.nodeValue;
var myDateObj = dateStringToObject(XPath.selectNodes(result[inc], "./date")[0].firstChild.nodeValue);
temp_data.date = myDateObj;
temp_data.time = XPath.selectNodes(result[inc], "./time")[0].firstChild.nodeValue;
temp_data.title = XPath.selectNodes(result[inc], "./title")[0].firstChild.nodeValue;
temp_data.header = XPath.selectNodes(result[inc], "./header")[0].firstChild.nodeValue;
temp_data.text = XPath.selectNodes(result[inc], "./text")[0].firstChild.nodeValue;
temp_data.image01 = XPath.selectNodes(result[inc], "./image01")[0].firstChild.nodeValue;
temp_data.ilink = XPath.selectNodes(result[inc], "./ilink")[0].firstChild.nodeValue;
temp_data.elink = XPath.selectNodes(result[inc], "./elink")[0].firstChild.nodeValue;
////////////////////////////////////////////////////////////////////////////
// PUSH INTO SORT
sort_array.push({id:temp_data.id, date:temp_data.date, time:temp_data.time, title:temp_data.title, header:temp_data.header, text:temp_data.text, image01:temp_data.image01, ilink:temp_data.ilink, elink:temp_data.elink});
//sort_array.push(temp_data);
///////////////////////////////////////////////////////////////////////////
}
for (i=0; i<sort_array.length; i++) {
trace(i+' '+sort_array[i].date);
}
///////////////////////////////////////////////////////////////////////////
sort_array.sortOn(sort_array.time)
trace("--------------------------------------------------------");
////////////////////////////////////////////////////////////////////////////
for (i=0; i<sort_array.length; i++) {
trace(i+' '+sort_array[i].date);
}
}
View Replies !
View Related
Performing A Sub Sort On A Multidimensional Array
Hi everyone,
I was wondering if you could help me please.
I have the following multidimensional array:
Code:
var bestSize:Array = new Array();
bestSize.push( { counter: small, order: "1", productSize: "S" } );
bestSize.push( { counter: medium, order: "2", productSize: "M" } );
bestSize.push( { counter: large, order: "3", productSize: "L" } );
bestSize.push( { counter: xlarge, order: "4", productSize: "XL" } );
bestSize.push( { counter: xxlarge, order: "5", productSize: "XXL" } );
I want to first of all sort the array in descending order on "counter". I then want to perform a sub sort on "order" to arrange the values in ascending order. I can peform the first sort by doing...
Code:
bestSize.sortOn("counter", Array.DESCENDING)
...or by creating the following function...
Code:
function sortBySizeCounter(counterValue1, counterValue2)
{
var a, b;
a = counterValue1["counter"]
b = counterValue2["counter"]
if (a > b)
{
return -1;
}
else if (b > a)
{
return 1;
}
else
{
return 0
}
}
bestSize.sort(sortBySizeCounter);
I would like to know if somebody could suggest a way in which I could perform the required sub sort.
I am fairly new to ActionScript so apologise if this sounds like a dumb question.
Thank you in advance for your help with this.
Kind Regards,
Joe
View Replies !
View Related
|