Sort And Returning A Boolean If The Actual Order Of The Array Has Changed
Hey guys
Is it possible to have the function that you are using to sort your array on return a boolean value of true if the array has at all changed?
Example:
I have an array = [1,2,3];
I use array.sort(myFunction) to sort it...
After the sort, the array is unchanged = [1,2,3].
Is there any way of returning a false value? I want some code to only run once the aray has been shuffled...
Any help would be appreciated!
ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 02-14-2007, 04:52 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
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
[MX04] Sort Array In Same Order Like Previous One
Hi all,
I am willing to sort an array in the same way like another array..
Explained: I have one array with x coordinates that I had sorted descending , now I have another one array , that I would like to sort (same order of indexes) like the first one..??
Thanx in advance for any answers
Meerah
Array Sort In Descending Order Doesn't Work
"Please use "Attach Code" to include any sample code in the message.". MMM. There's no attach code link.
The array.sort function doesn't sort in descending order, the output is the same.
Formatted: http://pastebin.com/f3a320622
//Ascending
var array = [{number:1}, {number:2}];
array.sort(function(a,b) {
if (a.number < b.number)
return -1;
else if (a.number > b.number)
return 1;
else
return 0;
});
array.trace();
Formatted: http://pastebin.com/m625c53df
//Descending
var array = [{number:1}, {number:2}];
array.sort(function(a,b) {
if (a.number < b.number)
return -1;
else if (a.number > b.number)
return 1;
else
return 0;
}, Array.DESCENDING);
array.trace();
Here's the additional functions (trace):
http://pastebin.com/f42937d95
Since they can't even fix the attach code thing, i have no hope they can fix this. But whatever.
Edited: 11/12/2008 at 03:01:58 AM by terraz73
Array.sort() With Custom Comparison Does Not Preserve Order Of Equal Elements
I have an array that I sort using a custom comparison function and I have discovered that sorting the array in this way does not preserve the order of elements that my comparison function judges as equal.
A simple example to illustrate this:
private function doCustomSort():void
{
var myArray:Array=[0, 1, 2, 3, 4, 5];
myArray.sort(customCompare);
trace(myArray);
}
private function customCompare(a:Number, b:Number):int
{
return 0;//any input will be judged equal
}
The trace output is "3,1,2,0,4,5". I expected the array to be left untouched if all elements were judged equal by the comparison function...
Any input on this would be much appreciated.
Prototype Function Returning Boolean
I have the following test code:
ActionScript Code:
_root.txtIn = function(str:String, txt:TextField):Boolean { try { var len = str.length; var index:Number = new Number(0); func = function () { if (index>=len) { clearInterval(si); return true; } index++; }; si = setInterval(func, 20); } catch (myError) { txt.text = myError; return false; }};
As you can see, it runs through several intervals before it actually returns a value. How would I go about evaluating it, if it always returns undefined before the interval ends? For example
ActionScript Code:
if(_root.txtIn(txtm, txtmain)) { trace(true);}trace(_root.txtIn(txtm, txtmain));
2nd trace returns undefined. Any ideas?
Sort XML Order?
I have a external XML link into the flash file.. is there a way to sort the display order of the XML data in flash?
Thanks so much!
Using "eval" Without Returning Actual Value...
So here's the deal, at the end of a function I want to take the value of a certain var and take one away from it. I do that successfully like this:
bullet1Life -= 1;
However, I want to put this in a loop, so that instead of just subtracting 1 from bullet1Life, I also subtract from bullet2Life, bullet3Life, etc. I have my loop all set up, and the way I try to write this line out is like this:
(eval("bullet" + [i] + "Life")) -= 1;
But the problem is, when I use that "eval" function it does indeed result in "bullet1Life" but it returns the current value of that var and not just the string. I then get an error message that states that the left side of assignment operator must be variable or property. Well, if it were simply returning "bullet1Life" instead of the value, it would be a variable.
Any suggestions?
Thanks in advance.
Flash5 Question: How Can I Sort Orders (order Form) By Numbers?
Hey flashers,
i have the following problem:
i want to make a simple order form in flash. that means that i
have to type a couple of orders into that form. BUT i do not
want to sort the numbers by myself. i want that flash is doing this
automatically.
these are my orders (manually typed into form)
_______________________________
Nr.62 laura biagiotti 100 ml
_______________________________
Nr.60 Yves Saint Laurent 100 ml
_______________________________
Nr.64 Armani Woman 100 ml
________________________________
after i clicked a button named [SORT NUMBERS]
following changes should appear:
Nr.60 Yves Saint Laurent 100 ml
_______________________________
Nr.62 laura biagiotti 100 ml
_______________________________
Nr.64 Armani Woman 100 ml
_______________________________
i just want to let flash sort the orders by numbers from 1-100
I would be very happy if someone could help me with the script
Thanks in advance
Niki
.
P.S.:If someone would write it for me i promise to give him 3x100ml
of wellknown designer perfumes from europe.you can choose between
100 different perfumes... Mybe this is a little motivation ;-)
Boolean Array?
hi there...
I'm setting up a preloader and so i can check if each section has loaded i need use a list of boolean variables from
loaded1, loaded2 ... loadedXX
do i use an array for this? or is there a way of appending a counter onto 'loaded' ?
thanks, for your help,
m
How Do You Set The Type(:Number, :Boolean, Etc) Of An Array?
i know, it's a simple question, but i've been looking around for a good ten minutes and all i can found about arrays is how to make them, via "var arraynamehere:Array=new Array()", and none of them are typed. can you even specify a type for an array? TIA ^^
Finding POSITION In Array - Not Just Boolean
I'm trying to find the possition of an elemtent within an array.
I'm currently work around this. It a button attatched in relation to the amount of items in an xml file:
this.onRelease = function() {
for (var k=0; k<array_length; k++){
checkARRAY = (_root.Nav_array[k])
//search through the array and get the possition of the currently clicked item
if(checkARRAY=this){
number_in_array.text = k
}else {
trace("not found")
}
}
}
What i'm trying to do is tell find the position of the currently selected item in the array so i can move the _y value of the items infront of it. Its a menu - all the other items would move down once i clicked the top item. I'm trying to make it all dynamic [from XML] so i can't refer to the items in the array without looping through it [i think].
If anyones got any ideas - it would be awesome!!
Turn A Array Of Variable Names Into Actual Variables
Hi all,
I have an array filled with the names of variables I created dynamically. I am trying to get these array items to act as the name of the variables while running through a loop but I get the error. "ReferenceError: Error #1069: Property text not found on String and there is no default value".
Flash sees the array items as strings rather than a list of variable names. I tried this a couple of ways but no matter how I hold these variable names they are in string form. So I guess what I really need is a way to convert a string to a variable name.
Here is the code I am using right now.
ActionScript Code:
for (var i=0; i<myMCArray.length; i++){
outXML += "<display_obj>";
outXML += "<value>"+myMCArray[i].text+"</value>";
outXML += "<pointX>"+myMCArray[i].x+"</pointX>";
outXML += "<pointY>"+myMCArray[i]y+"</pointY>";
outXML += "</display_obj>";
}
Thanks for the help my transition to AS3 has been a bumpy one.
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.
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
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.
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
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);
};
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?
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:
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
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??
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.
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
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
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??
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.
Associating Array Elements With Another Array Keeping The Order.
hi, i have already posted this problem yesterday but i haven't solved it yet.
i have two arrays:
array_1[a,b,c,d]
array_2[01,02,03,04]
the first array represents mcs in my stage - the buttons of the menu.
the second represents other mcs, containing some text.
when i rollOver each element of array_1 i would like to show each element of array_2 in the same order and hide it when i rollOver another menu button to show a new one.
I mean, it always has to be showing a with 01, b with 02, c with 03...
any suggestions?
Array Not Returning Value......
hi i'm new to flash kit but have being play with flash for a while.
Heres my problem:
on (keyPress "<Up>") {
hit = [main.hitTest("/wall0"),main.hitTest("/wall1"), main.hitTest("/wall2"), main.hitTest("/wall3")];
_level0.hittext=hit;}
this above returns the correct result to the "hittext" field ie.(false,false,false,false)
however this below returns (,,,)
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
hit = [main.hitTest("/wall0"),main.hitTest("/wall1"), main.hitTest("/wall2"), main.hitTest("/wall3")];
_level0.hittext=hit;}
Any help would be great thanx
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
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.
Array.sort By Letter?
Hello,
I have an array:
MyArray = a,b,c,d,
if an user press the letter d I would like the resort that array by:
MyArray = d,a,b,c
Thanks
Random Array Sort
does anyone have a script that randomly sorts an array of length n?
thanks,
dave
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
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
Array.sort Random?
Hi,
how can I use array.sort to have a random order in my array ?
thanks for any help
boombanguk
[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
[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
[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?
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.
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
AS3: How To Sort An Array Of Numbers
hi everybody.
I'd like any kind of tips on how to use ActionScript3 to sort an Array of Numbers.
i. e:
Code:
var _unsortedArray:Array = [34000, 77800, 12300, 11000, 21600, 33120, 18190, 43090];
any nice tips?
thanks
felisan
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!
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!
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.
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
|