Sorting Array?
Hi guys,
I'm trying to make an array and sort it alphabetically, how do I go about doing that? Thanks.
FlashKit > Flash Help > Flash ActionScript
Posted on: 01-17-2005, 02:57 PM
View Complete Forum Thread with Replies
Sponsored Links:
Sorting A New Array From An Existing Array (emergency)
Hi
i got an existing array, main[y], which after an equation, will come out with another array.
Code:
if (main[y] === topicList.getValue()){
subTopic = [];
subTopic = fTitle[y]
trace(subTopic)
}
However, i could not sort the subTopic, as it gkeep giving me undefined. Is there any way to sort this subTopic, such that they are in alphabetical orders?
Appreciate any help.
View Replies !
View Related
Sorting A New Array From An Existing Array
Hi
i got an existing array, main[y], which after an equation, will come out with another array.
ActionScript Code:
if (main[y] === topicList.getValue()){
subTopic = [];
subTopic = fTitle[y]
trace(subTopic)
}
However, i could not sort the subTopic, as it keep giving me undefined. Is there any way to sort this subTopic, such that they are in alphabetical orders?
Appreciate any help.
View Replies !
View Related
Sorting An Array
hi there a quick problem, not really had much exposure to arrays, Ive got 6 integers, which are times which then are placed into an array, Ive been trying to sort them in numerical order but really dont know how to tackle it am I meant to for and if test them all against each other the result are to be displayed in six text field (1-6).....
any help or direction would be greatly appreciated.
thanx in advance!
View Replies !
View Related
---Sorting ARRAY-----
Hey guys,
I have the Array (93,101,109,96,94.7,100.5)
So when I sort it it comes out like:
(100.5, 101, 109, 93, 94.7, 96)
In other words it takes the numbers from 100, sort it, and than it takes from 90.
Is there any way to fix it?
Thanks in advance.
Olga.
View Replies !
View Related
Array Sorting
I'm trying to work out a solution to searching through my xml and separating names out into different lists.
Basically I have a node called name. My problem is I need to separate the names out into arrays like this.
Code:
var A_F:Array = [];
var G_L:Array = [];
var M_R:Array = [];
var S_Z:Array = [];
In my xml load I have the names show up like
[code]
function loadXML(url) {
xmlList = new XML();
xmlList.load(url);
xmlList.onLoad = function(success) {
if (success) {
var rootNode = this.firstChild;
numberOfPioneers = rootNode.childNodes.length;
for (var i = 0; i < numberOfPioneers; i++) {
names.push(rootNode.childNodes[i].childNodes[0].firstChild);
}
trace("names :"+names);
}
};
}
loadXML("photo_list.php");
[code]
The trace("names :"+names);
output like:
Code:
names :Nick Arias,Don Blair,Andy Brizio,Jack Calori,Julian Doty,Jim Nelson,Wally Parks,Robert E. Petersen,Bob and Dick Pierson,Ed Pink,Phil Remington,John Wolf,Alex Xydias
No I need a way to search through the last name and take from var A-F, G-L, M-R, S-Z out and place them in there approperate arrays.
Any help on how I could achive this.
View Replies !
View Related
Sorting An Array
I need to sort an array. The array looks like this:
[[2],[a],[1],[d],[3],[e]]
I need the results to look like this
[[1],[d],[2],[a],[3],[e]]
In other words the number value is used to also order the letter value
Thanks
View Replies !
View Related
[F8] Help With Sorting Array...
I've set up a gallery that loads a php to pull each image file from a folder and send the result to flash, which then puts them into an array. I have a date portion that is also from php. My problem is in flash, trying to create this array so I can sort by date.
Here is the PHP:
PHP Code:
function returnimages($dirname=".") {
$pattern=".(jpg|jpeg|JPG|JPEG)$";
$files = array();
$curimage=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file)){
$filedate=date ("YmdHis", filemtime($file));
echo '{file: "'.$file.'", date: "'.$filedate.'"}'.'.:::.';
$curimage++;
}
}
closedir($handle);
}
return($files);
}
echo "&loadArray=";
returnimages();
And here is the AS:
PHP Code:
_root.folderPath = "Images/Portfolio/";
var imgCount:LoadVars = new LoadVars();
imgCount.onLoad = function(success:Boolean):Void {
if (success) {
var gal_str:String = imgCount.loadArray;
gal_array = gal_str.split(".:::.");
trace(gal_array);
} else {
trace("ERROR");
}
};
imgCount.load("myphp.php",imgCount,"GET");
stop();
I'm trying to get my array where I can use "sortOn" date. Any suggestions?
View Replies !
View Related
[CS3] Array Sorting
I have this sequence of numbers to be sorted:
Quote:
432534,5646,69855,234,1023,69855,12366,123,10339,7 780036,9803,22310,
69855,5633,0023,70002,600020...
when i use Array.NUMERIC | Array.DESCENDING, it sorts in this way:
Quote:
9803,7780036,70002,69855,69855,69855,600020,5646,5 6233,432534,234,22310,12366,123...... and so on
What i actually expect it to do is to sort the numbers in the order of its real value. Something like :
Quote:
7780036,600020,432534,70002,69855,69855,69855,2231 0,12366,10339,9803,5646,5633,234,123,0023
View Replies !
View Related
Sorting In An Array
I want to sort the elements of my object like so:
tile_mc0, tile_mc1, tile_mc2, tile_mc3, etc...
(like when i initialize them....)
for (i = 0; i < 16; i++)
{
tile_holder.attachMovie("tile_mc", "tile_mc" + i, i);
tiles = tile_holder["tile_mc" + i];
tilesPool.push(tiles);
}
the problem is after removing some elements of the Array and using the sort command :tilesPool.sort();
my array looks like this :
tile_mc0, tile_mc1, tile_mc10, tile_mc11, etc...
How do you sort this movie clips names ???
View Replies !
View Related
Sorting An Array (again)
I have a few movie clips on the stage and I have named them var1, var2 etc. What I want to do is to have them in an array and I want it to be sorted by depth. Here´s how I do:
Within a for loop i populate the array(sections) and assign the value(lvl) like this:
Code:
for(i=1;i<=4;i++){
this["var"+i].lvl = this["var"+i].getDepth();
sections.push(this["var"+i]);
}
And then I try to sort the array with:
Code:
sections.sortOn("lvl", Array.NUMERIC);
I trace out the array and get:
-16382
-16374
-16358
-16367
Obviously it´s not sorted... any hints?
View Replies !
View Related
Array Sorting
Hey all,
Im creating a game where you travel along a board picking up money and losing money. I was wanting to build a bank statement type thing where it stores each varaible you lost or gained in a ordered list as well as updating the balance.
for example:
balance £2000
won £50
balance £2050
payed credit card £300
balance £1750
anyone an idea of how to do this, im reckoning a sorting array but a bit stuck
Cheers
View Replies !
View Related
Sorting An Array
Hey all,
I can't seem to figure out how to sort an array of classes.
What i have is an array of my custom class Person. Person has the property Age. And I have an array of Person instances and I want to sort it by the Age property in a decsending manner.
I read about sortOn and tried
array.sortOn(array.Age, Array.DESENDING | Array.NUMERICAL);
and many other variations but it never worked on the whole array. On an array of 6 instances it would only sort the first 4, and they were Ascending.
So, there must a be a good way of sorting them, i tried a few loop combinations to sort it myself but it's trickier than i thought.
So can anyone please help?
Thanks.
View Replies !
View Related
Sorting Array Help
hey guys,
I have three arrays named: grRatio, grAlpha and grColor. They are indexed using movie clips, so grRatio for example is setup like something like this:
grRatio[some_mc]=value;
grRatio[another_mc]=value;
so if I do this:
ActionScript Code:
for (var index in grColor) {
trace(index+" color: "+grColor[index]);
}
for (var index in grAlpha) {
trace(index+" alpha: "+grAlpha[index]);
}
for (var index in grRatio) {
trace(index+" ratio: "+grRatio[index]);
}
This is what what I get in the output window:
Code:
_level0.grad_mc.co_mc3 color: 0x0033CC
_level0.grad_mc.co_mc2 color: 0x66CC99
_level0.grad_mc.co_mc1 color: 0x000000
_level0.grad_mc.co_mc0 color: 0x66FF00
_level0.grad_mc.co_mc3 alpha: 42
_level0.grad_mc.co_mc2 alpha: 82
_level0.grad_mc.co_mc1 alpha: 100
_level0.grad_mc.co_mc0 alpha: 72
_level0.grad_mc.co_mc3 ratio: 96.39
_level0.grad_mc.co_mc2 ratio: 56.61
_level0.grad_mc.co_mc1 ratio: 142.29
_level0.grad_mc.co_mc0 ratio: 195.84
Now what i need to do is take the values from these arrays and create 4 new arrays: "color_arr", "alpha_arr", "ratio_arr" and "movie_arr" and sort them in accending order using the values in the grRatio array.
I know I have to use a couple of for loops, but my tries have not worked so far...help!
View Replies !
View Related
Sorting Array
Hi,
I have a problem with sorting my array.
I use an array to load external thumbnails and pictures into my movie.
ActionScript Code:
var img_array = ["tp_01.jpg", "tp_02.jpg", "tp_03.jpg", "tp_04.jpg", "tp_05.jpg", "tp_06.jpg"]
var big_array = ["p01.jpg", "p02.jpg", "p03.jpg", "p04.jpg", "p05.jpg", "p06.jpg"]
I want to sort my thumbnails by number, at this moment when i publish my movie on my system he sort the thumbnails good, however when i publish the movie on my server it has a random order. I think he is loading the thumbnails on KB. I have used the sort function but this doesnt work, i think the sort function wil only work when the images are in the flash movie.
So my question:
How do i sort my external thumbnails in order by number?
Much thx to the person that can help me.
View Replies !
View Related
Sorting An Array
Hi
I need to sort and array like this:
[[3],[z],[1a],[f],[2],[k]]
to look like this:
[[1],[f],[2],[k],[3],[z]]
The numbers are used to determine the order of the letters
Thanks
View Replies !
View Related
Array Sorting
Hi,
I'm trying to sort an array by sorting in ascending order through a property of the array. For example, here is some pseudocode:
Sort arrayList by (arrayList.idNumber)
Is there a way to do this?
Thanks,
~Oni.
View Replies !
View Related
Array Sorting
I can't believe i'm asking a question ! It's been ages.
What i would like to know is how to sort arrays without using the `sort` function. even some psuedo code as to how to code your own sort function would be great.
Thanks - icio.
View Replies !
View Related
Sorting An Array
Is there a way to do a sort on one array, and then use the new order created as a result of the sort to sort a corresponding array/s?
say i have
ActionScript Code:
array1:Array = new Array("c", "e", "a", "d", "b");array2:Array = new Array("sfas", "weradfa", "asdf", "etw", "nvbncv");
if i sort array1, how can i make array2 match the new order of array1?
View Replies !
View Related
Sorting My Array
here is the deal I am dynamically populating my array with some dates like this:
1928,1930,1942,1945,1951,1963,1965,1966,1969,1979,1980,1980,1980,1980,1980,1990,1990,1990,2000,2000,2000,2000
this is no problem. how can i sort through these dates, i want to look through the array and say if I am on 1951 then the next one is 1963 and the previous one is 1945. really i just want to move to the next or previous item in the array, the names are not necessary as they may change. can anyone get me moving in the right direction for this??
thanks,
-brad
View Replies !
View Related
Sorting An Array
I need some help sorting an array. My app has a set of four radom number generators. My goal is to dump the results into an array, and then run a function that sorts the array in descending order. I tried a link to some code cold q.sort I found in the forums here, but I couldn't quite see the value. I performed the q.sort and nothing happened. Maybe I misunderstand sorting. Somebody give me some revelation please.
View Replies !
View Related
Sorting Big Array
Hi, I have some problem wich I would like to solve:
I made table in flash, with added functionality to sort table by columns. Now I have a problem - loaded xml data make about 300 records with sub arrays like array[(num, name, country)].
So now I need to sort this array, ofcouse I can use built in array.sort with compare function, as it is now. But I think that there should be some faster way. As far I'v looked over internet found nothing.
Any help would be preciated ....
You can see that table and test the speed of built in sort function here and source data here
View Replies !
View Related
Sorting An Array
Hello all,
I am hoping to start on a small project for school tomorrow and would like to know if it is possible to create a simple 'rankings table' in Flash. All of the numbers that I intend to display will be held as variables within the script (Actionscript 2.0) and so I do not need to use PHP or anything like that to access or store data.
If, for example, I had the following data:
Code:
team1Name:String = "Red Team"; team1Score:Number = 20; team2Name:String = "Blue Team"; team2Score:Number = 10; team3Name:String = "Green Team"; team3Score:Number = 30;
Could I adapt this data and put it in the form of a numerically sorted table? (See below)
Green Team __30
Red Team ____20
Blue Team____10
I was planning to do the following: put the data into an array and then sort the array numerically.
However, I am not sure whether this is possible or whether it would be the most effective way to create the table.
Any help wih the coding or advice that people could offer before I begin the project would be appreciated!
Thanks as always for any help,
David
View Replies !
View Related
Sorting Seperate Array's
Hello all.
i know how to sort arrays and do lotz of other cool stuff with it
BUT!
i have 2 arrays wich contains the following data
Mark 20
Steve 100
Erik 5
arraynames["mark","steve","erik"]
arraycash[20,100,5]
now here it comes, when i sort the cash array i wonna have the names array sorter in the same way
arraynames["steve","mark","erik"]
arraycash[100,20,5]
(just imagin this with 30 names/cash
any ideas? workarounds? any help appreciated, i tried a few ways by unshift and push to get them sorted in a diff way but it isn't fullproof
View Replies !
View Related
Sorting An Array Of Numbers
o man..flash is so annoying sometimes...
here's the deal..i have to sort a list of numbers..say :
temp = new Array (1,25,101,23,52,52,92,4)
everybody knows that is should generally turn out to be :
(1,4,23,25,52,52,92,101) or compeletely reverse depending on the sort right?
now, flash, when i use temp.sort(), it returns :
(101,1,23,25,4,52,52,92)
now isn't that queer?
any body got a solution?
help is GREATLY appreciated!
View Replies !
View Related
Array Sorting Question
Hi,
I have an array that I want to sort alphabetically, then have all the ones that have a name starting w/ a - l do a certain thing and then the m - z do something else. Make sense?
I know how to sort it alphabetically, I'm just not sure how to see what letter it starts with.
Thanks.
View Replies !
View Related
Specifically Sorting An Array
Hey folks,
Quick question...
I've got an array with several values in it... is there a way I can determine dynamically which value appears the most often in said array? For example:
myArray = new array("2", "4", "1", "7", "6", "4", "2", "3", "2")
As we can see, the value "2" appears the most in the above array... so how can I get Flash to dynamically see it too?
Thanks!
- Thingee
View Replies !
View Related
2D Array Sorting? (help Needed)
hello, returning to flash after a looong gap to do a new project. I'm having trouble figuring out how to achieve what i need with arrays.
I'll describe it in terms of a database analogy: what i'd like to do is have a table that holds 2 'fields' for each 'record'. The field would be 'name' (a string) and 'depth' an integer.
What i'd like to then do is sort the records in the table in order of 'depth' (from lowest to highest).
And finally, i'd like to iteratively work through the ordered reords, passing the 'name' and 'depth' values of each record in turn, to a function for processing.
If anyone could provide some sample code i'd be very grateful, this is frying my brain
View Replies !
View Related
Sorting Arrays Within An Array
hi there,
I have several values stored in multiple arrays (let's call these 'secondary arrays'). Each 'secondary array' is stored in one cell of another array ('main array'). The structure would look something like this:
Code:
mainArray(secondaryArray(number, textField, textField,...), secondaryArray(number, textField, textField,...), ...)
I was wondering if there was a way to sort the secondary arrays according to one of the values in them (namely the 'number')
Is that possible at all? Any help would be appreciated
Ta
View Replies !
View Related
Array Sorting Problems
I'm having a bit problem with an array. I have an array like this:
points = Array(1,5,7,2,15,2,2,3,24);
generated dymically, so it can be anything, numbers from 1-20.
what I need to do is to find out the biggest numbers on this array and somehow to get their keys in this array.
so that the final result would be keys: 8, 4, 2
( points[8], points[4], points[2] )
Did anyone understand my rumblings
Thanks.
View Replies !
View Related
Sorting An Array Of Objects
Hi,
I have this array of objects, each element of the array contains 3 properties, (link:String, level:Number, Count:Number). I want to sort my array ascendingly based on the 'level' property. Any idea how to do that?
Best Regards
View Replies !
View Related
[F8} Sorting Array Craziness
i need to sort arrays, which are loaded as variables via php.
however why wont this sort correctly? it wont put the 30.056 below 45.105
if i sort ascending, it still is incorrect. is there something im not seeing???
Code:
ranges = new Array();
ranges[0]=45.104;
ranges[1]=4.104;
ranges[2]=30.056;
ranges[3]=0.104;
ranges.sort(Array.DESCENDING);
c = ranges.length-1;
for (i=0; i<=c; i++) {
trace("range - " + ranges[i]);
}
output:
range - 45.104
range - 4.104
range - 30.056
range - 0.104
View Replies !
View Related
[MX] Simple (?) Array Sorting
Hi there
I was trying to do what I supposed it would be a simple array sorting, but I don't know what I'm doing wrong.
I have an array with several numerical fields of which I'd like to use three to perform a descending sort. The fields in question are "P", "PF" and "DIF". My intention was to use the "P" field as the main sorting criteria, and if there where two identical values for it, use the "PF" field as a second sorting criteria. Same would apply for the "DIF" value. Here's what I tried:
Code:
matriuClasLLIGA.sortOn( ["P", "PF", "DIF" ] , 18 );
You may see the results here the fields used are those listed in the columns. It doesn't work.
A closer version to my original intention, which sadly (and obviously) doesn't take into account the "PF" and "DIF" values was achieved by using this code
Code:
matriuClasLLIGA.sortOn( "P", 18 );
you may see the results here
Any help would be highly appreciated,
Thanks a lot
View Replies !
View Related
Sorting An Array With A Loop
I have an array of 500 items. Each one is a combination of 5 letters. "abcde" , "acdbe" etc. Many repeat themselves. I want to compare each item to the rest and find the unique ones and push them into a new array. So I want an array of one of each pattern. I have been trying to create a loop, or even a nested loop, but I can't seem to get 100% accuracy. Any ideas or help would be appreciated. I should have no more than 120 items if they are all unique. Thanks.
View Replies !
View Related
[F8] Sorting Array Numerically
hi guys...i am trying to sort an array numerically (1,2,3,4,etc). My output panel is giving me:
0.jpg,1.jpg,10.jpg,11.jpg,12.jpg,13.jpg,14.jpg,15. jpg,16.jpg,17.jpg,18.jpg,19.jpg,2.jpg,20.jpg,21.jp g,22.jpg,23.jpg,24.jpg,25.jpg,26.jpg,27.jpg,28.jpg ,3.jpg,4.jpg,5.jpg,6.jpg,7.jpg,8.jpg,9.jpg
so, here is the code i am working with:
Code:
function loadImages(xml) {
ims = [];
imRoot = xml.firstChild.childNodes;
for (var i = 0; i<imRoot.length; i++) {
ims.push(imRoot[i].firstChild);
}
ims.sort(Array.NUMERIC)
trace(ims)
}
i have tried moving the sort function in the for loop, before the loop, and a few other things...As well, being that really, my array is a set of strings, i tried ims.sort(Array.DESCENDING)....with that , i get
9.jpg,8.jpg,7.jpg,6.jpg,5.jpg,4.jpg,3.jpg,28.jpg,2 7.jpg,26.jpg,25.jpg,24.jpg,23.jpg,22.jpg,21.jpg,20 .jpg,2.jpg,19.jpg,18.jpg,17.jpg,16.jpg,15.jpg,14.j pg,13.jpg,12.jpg,11.jpg,10.jpg,1.jpg,0.jpg
not seeing what i am missing...can you help? thanks
View Replies !
View Related
[F8] Sorting A Multidimensional Array
I have an array thats stores an object;
chatters_arr = new array()
chatter = function(name, age, gender){
this.name = name
this.age = age
this.gender = gender
}
for(i=0;i<chatters.length;i++){
chatters_arr[i] = new chatter(
chatters.attribute.name,
chatters.attribute.age,
chatters.attribute.gender,
)
}
Now each time a chatter enters / leaves the room I will push a new object into the array or remove. Afterwards I want to sort the chatters alphabetically. How do I do this?
I know how to use the array sort, but how do I use it to sort the entire array based on the property of an ojbect stored inside?
Thanks.
View Replies !
View Related
Sorting Array After A Property
I have an array with some objects.
I want to sort my array after my obj_date_number.
trace("global_items_top = "+global_items_top[0][0].obj_date_number);
so the property excists, - but how do I sort my array after that property?
This doesn't work:
global_items_top.sortOn(["obj_date_number"],Array.NUMERIC);
Any idears?
Greetings
Godowsky
View Replies !
View Related
Custom Array Sorting
I'm using this array randomizer and I want to make an addition to it but not quite sure how to do it.
I want to set a variable for where to start the randomization
for example: I would set this variable to 3 if I wanted to keep a, b, c in order but randomize d, e, f. If the variable was 0 it would randomize all of them.
any ideas?
var randomNumber:Number;
function randomizeSequence(){
return Math.round(Math.random()*2);
};
var sequence:Array = [a, b, c, d, e, f];
sequence.sort(randomizeSequence);
trace(sequence);
View Replies !
View Related
Sorting An Array Of Objects
I've got an array of objects. I need to know the most efficient way to sort the array. I only need to be able to sort by integers.
For example...
Code:
playerPass = new Array();
playerPass[0] = new Object();
playerPass[0].Name = "T. Bag";
playerPass[0].Att = 3;
playerPass[1] = new Object();
playerPass[1].Name = "A. Nus";
playerPass[1].Att = 5;
Of course i've got way more objects and way more properties inside each object. I need to be able to choose which object property to sort the array by. Your help is appreciated, thanks.
by the way I'm using flash 8
View Replies !
View Related
Sorting An Array, Flip It?
is there a way to kinda flip-flop/reflect an array?
i'm bringing in xml and rather it displaying from top to bottom it's displaying from bottom to top..i have no idea why, haha..
so does anyone know a way to kinda flip it somehow?
View Replies !
View Related
Randomly Sorting An Array In AS 3.0
I am trying to populate an array with numbers 1-n where n is a variable upperLimit (of numbers in a game of Bingo) and then randomise that array (for each new game). In AS 2.0 to populate my array (range) at runtime, I would have used;
Code:
for (i=0; i<upperLimit; ++i) {
range[i] = i+1;
}
trace(i);
How's this achieved nowadays?!!
I'm hard coding the array (seems painful!) and here's the rest of my code
Code:
var range:Array = new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
var a:Array = range;
function shuffle(a,b):int {
var num : int = Math.round(Math.random()*2)-1;
return num;
}
var b:Array = a.sort(shuffle);
trace(b);
Also I know this is a much discussed topic in AS 2.0. What is your opinion on the best way to execute this in AS 3.0?
Appreciate any comments and help!
View Replies !
View Related
Sorting Array Question
I'm trying to sort two arrays based on thier -x position, I got the sort method code from foundation actionscript but I must be missing something because it's not working. Does anyone have any idea what? I've tried searching the forums but couldn't find anything...
ActionScript Code:
//sort arrays function
function sortX(element1, element2) {
if (element1._x<element2._x) {
return -1;
} else if (element1._x>element2._x) {
return 1;
} else {
return 0;
}
}
//
createSentence = function () {
for (g=0; g<usedWord.length; g++) {
name = usedWord[g];
if (Number(_root[name]._y)<40) {
row1.push(name);
} else {
row2.push(name);
}
}
row1.sort(sortX);
row2.sort(sortX);
};
View Replies !
View Related
Sorting An Array Of Dates
Hi folks,
If anyone can point me in the direction of a way to sort an array of dates, I would be most grateful.
e.g. array containing 19/06/2004,15/05/2004,17/05/2004,08/05/2003 sorted to result in 08/05/2003,15/05/2004,17/05/2004,19/06/2004
Thank you
View Replies !
View Related
Quick Array Sorting Help.
Hi All.
Was just wondering if someone could help me out with a sorting function.
I have an array 'EventData'
Within 'EventData' are objects:
{_subject, _start, _end}
_start and _end are both Date Objects, and what I need to do is sort the array by the _start & _end dates (date and Time)
Kinda confusing to describe here, but this is how it would need to end up.
Dates with a _end greater than _start
Dates where _start == _end & same Time
Dates with same Dates and _start time is greater than _end Time
Could anyone help?
Cheers.
View Replies !
View Related
Sorting An Array Of Objects
I know this is probably really easy to do but I'm just stuck... someone plz help me along.. I have an function that accepts an Array of objects and sorts them according to a property that holds a numerical number. However, I don't know what to add exactly so that once the object with the highest property is chosen, it wont be rechosen again.... here is my code...
Code:
function SortBySpeed(array){
var return_order = new Array()
var highestindex = 0
for(var i=0;i<array.length;i++)
{ var highest = 0;
for(var k = 0;k<array.length;k++){
if(array[k].speed > highest){
highestindex = k
highest = array[k].speed
}
}
return_order[i] = array[highestindex]
// i dont know what to put here!!!
}
return return_order
}
View Replies !
View Related
Sorting MovieClip Array Using _x
I have an array of movieclips "vLineArray" which I'm trying to sort based on the movieclips x position (_x). The following is not working:
vLineArray.sortOn(_x, Array.ASCENDING | Array.NUMERIC);
Can anyone suggest how I can make this work?
Thanks!
View Replies !
View Related
Randomly Sorting An Array
Okay, I have a string array that contains answers to multiple questions. In my example data I'm working with, there are always 3 responses in the array. I want to write them out to the screen in random order, since when the array is created the "correct" answer is always array position 0 (ie, the first one).
The array is called "responsesArray". I was using the attached code to try to create a new array called "sortedResponsesArray".
It APPEARED to be working, but then I noticed that it seemed like the first answer was the correct answer an inordinate amout of times. So I did some testing by running it over and over a couple of hundred times, and in fact it does not appear to be returning random results. The first position in sortedResponsesArray IS in fact the correct answer way too often for it to be random. It appears to be about a 25-5-1 ratio. Ie, if I run it 31 times, 25 times the correct answer will be in the first position of sortedResponsesArray, 5 times the correct answer will be in the second position in sortedResponsesArray, and 1 (or maybe 2) times the correct answer will be in the third position in sortedResponsesArray. It's not an EXACT ratio, but it's close to that...
Just wondering if anyone can see anything wrong with my sorting logic and/or can suggest anything better..
Thanks!
Mike
Attach Code
Given this as some example data, the real data comes from an XML file:
responsesArray[1] = "The right answer";
responsesArray[2] = "A wrong answer";
responsesArray[3] = "Another wrong answer";
function shuffle(responsesArray,sortedResponsesArray):Number {
var num : Number = Math.round(Math.random()*2)-1;
return num;
}
var sortedResponsesArray:Array = responsesArray.sort(shuffle);
I then do a simple loop through sortedResponsesArray to output the answers to the screen...
View Replies !
View Related
Sorting Multidimensional Array
I have an array of objects (the first member of each object is a string which records the object's name) The other members of the objects contain various numerical information. I need to sort each category of information and display the names next to their related information in correct numerical order:
ie. AName 4235
AnotherOne 3962
OneMore 1576
Can anyone suggest some code which would do this? I checked out .sort and .onSort, built in methods of array but I can't get my head round it.There are thirteen objects in my array. The fourth element (population) needs to be sorted. I tried
x=0;
for (i=0;i<14;i++) {//counts through objects in array
if ( EmpireList [i] [3] >x)
x= EmpireList [i] [3];//loops through array to find greatest numerical value
} //and writes it into x
LargestInArray = x;
This gave me the biggest numerical element in the array. I figured I needed some kind of nested for loop to find the next largest and so on but I can't get it to work.
Ideally I need to copy the information into a new array with two dimensions (for name and information)
Thanks
MD
View Replies !
View Related
Sorting Array By Id And Parent Id
hi,
Im building a flash menu/section system for a cms. Im have a
little problem of sorting a array. The array get its rows from
a mysql db, im using PHPobject to get the sql records in flash.
MySql table has following colums; id, title, parent-id. When all
is stored in a flash array it look likes this;
row id, title, pid
[0] - 34,2005,0
[1] - 35,Nyheter,34
[2] - 36,Om Brasswind,34
And here comes my problem, when i attach movieclips i get linare
menu if you understand, but what i wont is a three-menu look at it,
like this;
2005 (id 34 pid 0)
|
+- Nyheter (id 35 pid 34)
|
+- Om Brasswind (id 36 pid 34)
Is possible to sort array this way? any advices..
her is my code used to get the 'linare' kind;
Code:
function viewSectionRecords(){
for (var i=0; i<sectionRow.length; i++){
var item_obj = this.createEmptyMovieClip ("item_holder"+i, i);
item_obj._x = 120;
item_obj._y = 145;
var holder_obj = item_obj.attachMovie ("section_item_mc", "section_item_mc"+i, i)
holder_obj._x = 0;
holder_obj._y = 7 + ((holder_obj._height * i)+3);
holder_obj.item_txt.text = sectionRow[i][1];
}
}
View Replies !
View Related
Array Sorting Problem
Hi!
I've got an Array, which has elements that are in the array multiple times.
Now, id like to sort out the elements into a new Array so every element of the first one apears only once in the second one.
How sould i do this? It seemed prety easy for first blink, but now it's driving me mag.
Thanks for any help.
St.
View Replies !
View Related
|