Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash








I Need A Sorting Algorithm - Comparing 2 Arrays


Hello,

I'm trying to compare 2 arrays and find all the unique elements of the 2nd array that doesn't match the elements of the first array.

I'm trying this but I keep coming up w/ data that matches that's actually supposed to show as a non-match (if that makes any sense).

Here's what I'm trying so far:



Code:
for( var i:Number = 0; i < _root.swf_names_array.length; i++ )
{
for( var j:Number = 0; j < _root.txt_names_array.length; j++ )
{
if( _root.swf_names_array[i] == _root.txt_names_array[j] )
{
trace( "Matches" );
break;
}
else
{
trace( " No match here" );
not_found_array[j] = test_swf_name[0]; // add all non matches to the not found array

}
}
}
I just don't know why this is hard - maybe I need more sleep.

Thanks for any time!




FlashKit > Flash Help > Flash Newbies
Posted on: 08-22-2006, 12:51 PM


View Complete Forum Thread with Replies

Sponsored Links:

I Need A Sorting Algorithm - Comparing 2 Arrays
Hello,

I'm trying to compare 2 arrays and find all the unique elements of the 2nd array that doesn't match the elements of the first array.

I'm trying this but I keep coming up w/ data that matches that's actually supposed to show as a non-match (if that makes any sense).

Here's what I'm trying so far:


Code:

for( var i:Number = 0; i < _root.swf_names_array.length; i++ )
{
for( var j:Number = 0; j < _root.txt_names_array.length; j++ )
{
if( _root.txt_names_array[i] == _root.swf_names_array[j] )
{
trace( "Matches" );
break;
}
else
{
trace( " No match here" );
not_found_array[j] = test_swf_name[0]; // add all non matches to the not found array

}
}
}
I just don't know why this is hard - maybe I need more sleep.

Thanks for any time!

View Replies !    View Related
Sorting Algorithm Needed
does any one have an algorithm to sort 3 integers in an array

View Replies !    View Related
Simulation To Sorting Algorithm
hi everyone,i'm new in this forum & new to flashMX also, i need to do a trotorial that explains the "selection sort" algorithm, i need to use an array & variables to pass them to a function sort(); and when a user clicks button start, it starts working
thnx in advance

View Replies !    View Related
Flash MX 2004 (AS2) - Comparing And Sorting Lots Of Variables
HI!
I'm making a game in Flash MX and i have got stuck.
Game has 10 players and they all answer questions (answer: YES or NO).
Each player has it's own array for answers (player one's answers for example: answers1_array = [yes, no, no, no, yes, yes])
I get stuck, when i'm tring to compare these answers to find 2 players with most similar answers(2 players, who have most questions with same answer).
To compare, i use this code:

Code:
m1 = 0;
b1 = 0;
while (m1<questions_array.length) {
if (answers1_array[m1] == answers2_array[m1]) {
b1++;
}
m1++;
}

where questions_array contains all the questions and b1 is the count of same answers.
To compare all the players i need about 44 variables to store the number of similar answers (player1 to player2, then player1 to player 3, then player1 to player 4 etc). Then i'd have to compare all these 44 variables to each other, to find out, which variable is the biggest. I could use arrays to sort, but then i could not identify the 2 players, who have those answers.
I need the game to mark those 2 players, who have the most similar answers and by using 44 variables, it would get TOOO long.

If anything is unclear or confusing, feel free to ask, but please help or guide me to a better direction.
Thanks.

View Replies !    View Related
Comparing Arrays
I have two arrays and each will have between 1 and 5 values stored in them what I need to do is compare the two arrays. What I need is to compare the first array to the second one and have it output what value In the first array is larger then all the values in the second array. For example the first array would be 2, 3, 1, 4 and the second would be 2, 1, 3 so the output would give the info that the forth value is higher then all the values in the second array. I hope I have explained my self well and what I am trying to do is possible.

View Replies !    View Related
Comparing Two 2D Arrays
I have a function placed in a layer named actions that compares two 2D arrays. The array definitions also reside there. One of the arrays is updated by user input at runtime.
I wanted to attatch the function to a button but it does not work properly unless I also put the array definitions in the on(release){}. Here is the code:

function compareArrays(a1,a2) {
var wrong = 0;
for(var i=0;i<a1.length;i++) {
for(var j=0;j<a2[i].length;j++) {
if(a1[i][j]!=a2[i][j]) wrong++;
}
}
this["input" + i].border = "TRUE";
this["input" + i].borderColor = "0xFF0000";
trace(wrong ? "OH NO! "+ wrong +" wrong!" : "Correct!");
}
compareArrays(twoD_Array,myArray); // these arrays are defined in actions layer

on the button:
on(release){

compareArrays(twoD_Array,myArray);

}//does not recognise updated values to the array unless i include array definitions here I thought functions were to prevent redundant code?

View Replies !    View Related
Comparing 2 Arrays
Hi Folks

I need to match 2 arrays and see if the elements inside the array are same in both of them. For some reason the following code does not work
The problem is as soon as the first element inside each array is matched "trace correct" is being called. I want the correct trace to be called when all the elements of array have been matched. Can i write an extended class so that i can use it in multiple places
Thanks

RG

var correctArea = new Array("a", "b", "c", "d");

var correctItems = new Array("b", "c", "a", "d"); // These are for examples only, in real they will be added dynamically


CheckAnswer_btn.onRelease = function(){
correctArea.sort();
for (i=1; i<correctItems.length + 1; i++){
for (j=1; j<correctArea.length + 1; j++){

if(correctItems.length == correctArea.length){

if (correctItems[i] == correctArea[j]){
trace("correct");
popup.gotoAndPlay("correct");
//break;
}else{
popup.gotoAndPlay("Incorrect");
break;
}
}else{
trace("incorrect");
popup.gotoAndPlay("Incorrect");
break ;
}
}
break ;
}
};

View Replies !    View Related
Comparing Two Arrays
I've got two arrays (of objects) and I want to test whether they (or, rather, their contents) are equal.

Essentially, I'd like this to work:

if (ary1 == ary2) {
// the same stuff in each array
} else {
// not the same stuff
}


(ary1 == ary2) is always false, even when their contents are exactly the same. I think this is because when testing equality between two non-primitive datatypes, each must be references of the same array to be equal.

I could loop through the arrays and test (ary1[i] == ary2[i]), but since they are arrays of objects, I seem to have the same problem. The objects never equal eachother, even when they have the same properties with the same property values.

Seems like there should be an easy way to do this. Any suggestions?

View Replies !    View Related
Comparing Arrays,
ive got 2 sets of numbers. one are numbers chosen by a user, the other are randomly generated numbers.

how do i go about comparing both sets, and identifying when there is 1 match, 2 matches, 3 matches and so on.

help would be greatly appreciated

View Replies !    View Related
Comparing Arrays
ok lets give this a try.....

I have an array called 'correctListArray' that looks like this:


ActionScript Code:
correctListArray = ["call reminder","do not call","repeat dialing"]

I have another array called 'productList' that is constructed during the activity. Lets say that based off of the user's interactions that the 'productList' array looks like this:


ActionScript Code:
productList = ["do not call", "call rejection", "personal ring","call reminder"]

I have a textfield call correct_list. This textfield displays the correct answers (the correctListArray). What I'm trying to do, with little success, is compare correctListArray with the productList and if the array element is located in both arrays make the text in the textfield green. So in this example my textfield would look like this:

call reminder
do not call
repeat dialing

Notice repeat dialing is not green because it's not in the productList array generated during the activity.

How would I go about doing this?

I've tried:


ActionScript Code:
for (i=0; i<correctListArray.length; i++) {
    for (j=0; j<productList.length; j++) {
        if (correctListArray[i] == productList[j]) {
            _root.ourList.correctList += "<font color="#00cc00"><b>"+correctListArray[i]+newline+"</b></font>";
        } else {
            _root.ourList.correctList += "<b>"+correctListArray[i]+newline+"</b>";
        }
    }
}

But as you can plainly see this won't work.

View Replies !    View Related
[MX] Comparing Arrays
hi

i was wondering if its possible to compare two arrays to see if they are the same. ive tried it like this,

Code:
array1 = [bob,ted];
array2 = [bob,ted];

if(array1 == array2){
trace("monkey")
}
but do not get monkey returned

can i compare arrays and how do i go about doing it? thanks for any help

View Replies !    View Related
[MX] Comparing Arrays
hi

i was wondering if its possible to compare two arrays to see if they are the same. ive tried it like this,

Code:
array1 = [bob,ted];
array2 = [bob,ted];

if(array1 == array2){
trace("monkey")
}
but do not get monkey returned

can i compare arrays and how do i go about doing it? thanks for any help

View Replies !    View Related
[F8] Comparing Multidimesional Arrays
Hi,

I am trying to compare values in multidimensional arrays,
but I'm so confused and pulling my hair out!
I've been through the related threads on this forum and tutorials,
but no luck.

Here are my arrays:


Code:
var p1Array:Array = new Array();
var p2Array:Array = new Array();

p1Array[0] = Array("KW_match", 10);
p1Array[1] = Array("KW1", 15);
p1Array[2] = Array("KW2", 20);

p2Array[0] = Array("KW3", 25);
p2Array[1] = Array("KW4", 30);
p2Array[2] = Array("KW_match", 35);

trace(p1Array[0][0]); // returns "KW_match"
trace(p2Array[2][0]); // returns "KW_match"
I want to compare only the FIRST value of each array.
In the above test, "p1Array[0][0]" and "p2Array[2][0]" woulld be
the match.

Then I start to screw up...


Code:
Array.prototype.sameAs = function(array2) {
if (this.length != array2.length) {
return false;
} else {
for (var j = 0; j<this.length; j++) {
for (var k = 0; k<this[j].length; k++) {
if (this[j][k] != array2[j][k]) {
return false;
}
}
}
return true;
}
};

//returns "true", which really is "false"
trace(p1Array[0].sameAs(p2Array[0]));

//returns "undefined"
trace(p1Array[0][0].sameAs(p2Array[0][1]));
I'm assuming some process in this nature is needed, but
can't figure it out.

Could someone please help me!

View Replies !    View Related
Comparing Contents Between Two Arrays
Hi. I've tried to find this on my own, but have not had much luck, so I hope somebody can help me out.
I have 3 arrays. All three have a set of numbers(integers) in it.

1. Is there a way to compare arrayA with arrayB to see if there are any matching numbers between the two of them? They don't have to be at the same index number, just anywhere within the arrays. ?

2. And then, if there are matching numbers, take that number(s) and see if it exists anywhere within a third array (arrayC). If it does, then I want to swap out that number from the third array and replace it with something else. I think I know how to do the swapping, I'm just not sure how to capture that value from the first step.

Thank you very much for any help you can give me.

--cindy

View Replies !    View Related
Comparing Strings In Arrays
Hi everyone,

a shirt question, how would you compare whether one element from an array is contained in another array?

I guess the code would look something like this


Code:
for (var i = 0; i<my_WordArray.length; i++) {
if (my_WordArray[i] == greeting_array) {
trace("greeting invovled");
}
}
But then again I know something is out of place... Just can't seem to understand what

View Replies !    View Related
Comparing / Searching Arrays.
Greetings. Let me first say this is my first post, and I did search the forum and I found a great explenation on how to find a value in an array, but my problem is a little different and I'm not smart enough to figure it out on my own.

I have a random picture-script that, not surprisingly, shows random pictures.

Basically I have one array with all the imagenames which i shuffle every time the image is going to change.


Code:
pic_arr = ["images/1", "images/2", "images/3", "images/4", "images/5", (.....) "images/55", "images/56", "images/57"];
And one array that keeps track of every image that has been displayed.


Code:
function shuffle(a,b){
return random(2);
}
pic_arr.sort(shuffle);
holder_mc1.loadMovie(pic_arr[0]+".jpg");


i = folder.length;
folder[i] = pic_arr[0];
So after the image has changed a three times, the folderarray looks something like this.


Code:
folder = ["images/21", "images/12", "images/43"];

Now I need a script that will select a value from pic_arr that ISN'T a value in folder. I've tried for a few days now but I've gotten nowhere.

Please help?



Thank you in advance.

View Replies !    View Related
Sorting Arrays...2-Dimensional Arrays
How would I go about sorting two dimensional arrays using the sort() function. What I'd like to do is organize the arrays inside of an array by a certain variable...

i.e:

array1 = new Array("Name", "State1", "Cost");
array2 = new Array("OtherName", "AnotherState", "OtherCost");
array3 = new Array("DifferentName", "YetAnother", "AndAnother");
allarrays = new Array(array1, array2, array3);

Now, let's say I want to sort the arrays in allarrays by their state variable. In other words, I want to sort them so allarrays would look something like this (if sorted by state):

allarrays:
array2,
array1,
array3

Any suggestions or past experiences with this sort of sorting? Would I use the Sort() fuction? or would I have to make my own sort function? Thanks in advance for any help you can provide.

View Replies !    View Related
Comparing Arrays To Input Text
Hi all,
I'm stuck on shortening my code to compare arrays to text entered by the user.

I am using Flash 5.

My flash file has the following elements: "myHello" (Dynamic text), "myName" (Input text) and a Submit button (Action code seen below).

Here's the code for the Submit button.
----------------
on (release) {
var Name = new Array();
Name[0] = "Peter";
Name[1] = "Paul";
Name[2] = "John";
if ((myName == Name[0]) || (myName == Name[1]) || (myName == Name[2])){
myHello = "Go away, " + myName;
}
else {
myHello = "Hi, " + myName;
}
}
----------------

As you can see, when the submit button is clicked on, it creates a new array 'Name'. Then it compares the Input text 'myName' to the 'Name' array. If any of the names Peter, Paul or John is submitted, the dynamic text 'myHello' would say "Go away, Paul". If anything is entered, it would say "Hello, just about anything else".

I would like to shorten my code, that instead of
"if ((myName == Name[0]) || (myName == Name[1]) || (myName == Name[2]))"

it could be
"if (myName == Name[0..2]) {" (e.g. from array 0 to array 2)"

but it didn't work. The Flash file can be found at:
http://www.greenbank79.freeserve.co....raysindex.html

There are zipped and non zipped files.

Can you, please, help me out?

Cheers,
John

View Replies !    View Related
Comparing And Acting On Differences In Arrays
First of all, let me state that I'm a bit over my head at the moment. I'm a newbie with arrays, but need to do something fairly complex (at least it looks that way to me) very quickly (high-profile deadline is fast approaching).

OK, here's what I'm trying to do. I have a Flash navigation bar within a video player application. I'm using thumbnails pulled from a XML file (along with their corresponding links, headline, caption, etc.). Loading up the file isn't a big deal, but updating the navigation when new content is detected in the XML is proving to be a challenge for me.

Here's the direction I've been heading... I've got two arrays. The first contains all of the data for the navigation (thumbnails, headlines, links, captions). Once the nav bar is built with the XML data, the array is duplicated.

array2 = array1;

Every 30 seconds, I load the XML file into the first array and compare it to the second array (a mirror of the current nav) using a nested for loop.

for (var j = 0; j < array1.length; j++) {
for (var k = 0; k < array2.length; k++) {
//
}
}

At this point, I'm kind of stuck. I assume I need to create an array for all of the thumbnails that have been deleted from the XML, one for the thumbnails that have been changed and one for the thumbnails that have been added. Once I have that data, I can (somehow) us those arrays to change my navigation to its new state.

This may sound like I'm over-complicating the process, but what I want is to be able to animate the edits, so that when a new thumbnail is added, it pushes the others over and animates in... You know, eye candy.

Anyone have any ideas? I'd be very appreciative!

View Replies !    View Related
Problem Comparing Arrays With Variables
Hello,

I'm new in ActionScript, and I would want to make an application that sees if the text entered by the user is in an array.

So, if the array contains ("one","two","three") and the user writes "one" -> yes.
If the user writes, for example "five" -> no.

I've got a button "Search", a textfield with its variable (called 'usertext') for the user to insert text, and another textfield, a dynamic one (with its variable called 'dynam'), to see if the text that the user has written is in the array.

In the frame I've got this code:

fscommand("fullscreen","true");
numbers = new Array ("one", "two", "three", "four");


In the button I've got this code:

on(release) {
for(i=0;i<numbers.length;i++) {
dynam += "
"+numbers[i]+" - "+usertext+": ";
if(numbers[i] == usertext) {
dynam += "yes";
} else {
dynam += "no";
}
}
}


So I try writting "two" and what I get is:

one - two : no
two - two : no (this should be YES!)
three - two : no
four - two : no


What am I doing wrong?

Sorry for my English, if you don't understand something please tell me and I'll try to explain it better.

Lots of thanks!

View Replies !    View Related
Sorting Arrays
Can someone please help me with this problem...
My problem is that i need to be able to sort out 5 numeric answers and display them from highest to lowest (which i got to do so far), but the catch is i need the array value to be displayed aswell...
ie:
question1 = 50
question2 = 45
question3 = 24 ect.

If anyone could help, much appreciated...

Code so far...

on (release) {
_root.MyArray = [_root.question_1, _root.question_2, _root.question_3, _root.question_4, _root.question_5];
trace (_root.MyArray.join());
_root.MyArray.sort();
_root.MyArray.reverse();
trace (_root.Myarray.join());
_root.highval = (_root.MyArray[0]);
trace (_root.highval);
_root.midval = (_root.MyArray[1]);
trace (_root.midval);
_root.lowval = (_root.MyArray[2]);
trace (_root.lowval);
i = 1;
while (i<6) {
if ((_root.question_(i))==(_root.highval)){
_root.highest = ("question_" + i);
} else {
_root.highest = "Need the var here";
}
i = (i+1);
}
}

View Replies !    View Related
Sorting Arrays
Hi,

I have three arrays:

names[];
values[];
othervalues[];

these arrays are synchronised. I mean:
names[5] belongs with values[5] and othervalues[5].

The problem is, I'd like to sort an array, but I can't use the build-in sort command. Why? Because if I e.g sort array names[] and sort array values[], the values don't match anymore. The array are sorted seperately.

I'd like to do this:
In case of sorting by name: sort the array names[] and apply the same ID changing with the other two arrays.

I hope you understand what I mean. Does someone has the answer? Thanks!

View Replies !    View Related
Sorting Arrays
Does anyone out there know how to sort a sub array based on one element within it? I have an array which contains a number of sub arrays. The sub arrays each have an element consisting of a single number. I need to sort the sub arrays within the "mother" array using this number as the key.

Any ideas?

View Replies !    View Related
Sorting Arrays.. :S
I have made me a manual sort function, because the normal sort function, and the sortOn function return resuolts like this

6,54,5,45,45,23,12,12

but nooo! mine does it too, any ideas?

ActionScript Code:
function mSort() { for (var i = 0; i<nest.length; i++) {  for (var j = 0; j<nest.length; j++) {   if (nest[i]>nest[j]) {    var temp = nest[j];    nest[j] = nest[i];    nest[i] = temp;       }   trace(nest[i])  } } show = nest}



help needed, must be easy, and im overlooking it

View Replies !    View Related
Sorting Arrays
Does anyone out there know how to sort a sub array based on one element within it? I have an array which contains a number of sub arrays. The sub arrays each have an element consisting of a single number. I need to sort the sub arrays within the "mother" array using this number as the key.

Any ideas?

View Replies !    View Related
Sorting Arrays (bit Longwinded Sry:) )
Hi, i have abandoned my own sorting function, and am now trying to use the built in method. but on testing the script causes the comp to freeze and comes up with the abort script message. heres what i am trying to do:

the user clicks the clip, and the x coords are stored in _root.xcoords. i have a number of randomly positioned duplicate clips and i need to get their distance from the users click (only x at the mo), so i subtract the xcoords of the users click from the duplicate clip positions and store in an array. to get rid of negative distances i square then square root all values in the array. (done via the loop, where _root.i represents the number of duplicated clips. (this all works ok)

what i really need is the names of the clips listed in order the of their proximity to the click (so later i can change say the nearest 4 clips properties). so i add ":object" + j to the distance (which adds the name cos when j increments it goes through in order.)

my plan is to then sort the array xdistancefromcursor by the proximity to the users click, so that i can later determine the names of the clips. i.e. xdistancefromcursor[0] would contain something like: 1345.645:object0 . the search must only consider 1345.645.

heres the code:

onClipEvent (load){
xdistancefromcursor=new Array();
}
onClipEvent (mouseDown){
function order (a, b) {
// Entries to be sorted are in form
// name:password
// Sort using only the name part of the
// entry as a key.
name1 = a.split(':')[0];
name2 = b.split(':')[0];
if (name1 < name2) {
return -1;
} else if (Number(name1) >Number(name2)) {
return 1;
} else {
return 0;
}
}

_root.xcoords=_xmouse;
//gets distance of each object from the mousecursor, makes positiove and stores in an array.
j=0;
while(j<_root.i){
xdistancefromcursor[j]=(_root.xcoords)-(_root.objectxcoords[j]);
xdistancefromcursor[j]=Math.sqrt(xdistancefromcursor[j]*xdistancefromcursor[j]);
xdistancefromcursor[j]=xdistancefromcursor[j] + ":object" + j;
j=j+1;
}
xdistancefromcursor.sort(order);
}

the latter part up to the sort command works ok, so the problem seems to be in the order function (which i took straight from the help file). I cant for the life of me figure out whats wrong here, so if anybody has any ideas i would be v. grateful.

thx in advance

bob.

http://www.sensoriumdesign.net/

View Replies !    View Related
Sorting 2D Arrays --ahhhhgggghh
Howdy,

Last year I went crazy figuring out a way to sort 2 dimentional arrays. I made it work, but it was slow as hell. A programmer friend of mine checked out the code and said that I'd made a "bubble sort". That's great. Anyway, it doesn't workin MX. Does anybody know a way to sort 2D arrays? Do I use qSort, recursion,...? Anybody? It's not for a specific project; its just a general need, and a function I'd like to be able to use.

here's some of my old sorting code (flash 5). some of the variables are undefined. it's pretty crappy as I'm much better at abstracting now, but you'll get the general idea:

<PRE>

function sortList(column) {
i = 0;
while (i<listLength) {
v = list[i];
vv = 0;
c = column;
while (vv<c) {
v.sort(0);
vv++;
}
i++;
}
//
list.sort();
//
if (column != 0) {
i = 0;
while (i<listLength) {
v = list[i];
vv = 0;
c = column;
columCount = _root.word_0.length;
while (vv<columCount-column) {
v.sort(0);
vv++;
}
i++;
}
}
}

</PRE>



i give up- i can't get flashkit to display the code correctly. if anyone knows how to display the code without it being ruined by Flashkit, let me know please.

tutash
[Edited by tutash on 08-08-2002 at 01:37 PM]

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
Duplicating Arrays/sorting
Hello world...

basically im trying to make an xml driven database that is searchable by multiple criteria. I have it so it grabs models from an xml file and displays all their information etc...
In order to enable a search for like blue eyes, female, with blond hair...im trying to create a number of arrays that read/write from each other.

Thing is, i can make a 'for' statement that parses through the array and 'if' there is a match it writes it into a new array. now...
it works ok in flash 6.0 as2 and earlier...when i export in 7...all the values in the new (copied) array are undefined.

//function that grabs blueeyed models from array named articles and writes to a new array articlestemp. (article is an object defined earlier to hold the xml data for a model)

function blueeyesf() {
var id, pic, name, age, height, eyecolor, gender, email, phone;
tempcount = 0;
isblue = 0;
for (w=0; w<articles.length; w++) {
trace("eyecolor: "+articles[w].eyecolor);
if (articles[w].eyecolor == "blue") {
isblue = 1;
tempcount++;
id = articles[w].id;
pic = articles[w].pic;
name = articles[w].name;
age = articles[w].age;
height = articles[w].height;
eyecolor = articles[w].eyecolor;
gender = articles[w].gender;
email = articles[w].email;
phone = articles[w].phone;
} else {
trace("they aint blue");
}
if (isblue == 1) {
newtempArt = new article(id, pic, name, age, height, eyecolor, gender, email, phone);
articlestemp.push(newTempArt);
delete newTempArt;
isblue = 0;
}
}
}

//this is the syntax i used for array declaration
var articlestemp = [];

any help would be much appreciated.

View Replies !    View Related
Problems Sorting Arrays
Allright, I'm making a little platformshooter in my first shot at AS3. I'm using lines to define my terrain and the trajectory of a shot. My sprites look like moving circles so I just use a basic distance from a point to a line calculation to detect hits. This makes the math relatively simple as everything can be written as a linear function. The picture probably explains more

Using this form of hit detection, I get all the hits on sprites/terrain left or right of the sprite firing the shot in the form of an array. I then want to sort the array to have the object (be it a line of terrain of a bad guy/player) that's nearest at the start of the array. Since it's all lineair functions, I use the x position for this. If I'm shooting right, the one with the smallest x position is the hit. If I'm shooting left, the one with the biggest x postition is the hit.

The problem is, that my sorting functions give me some really weird output. If anyone would care to take a look, I'd really appreciate it.


Code:
public function OrderLowest1(a, b) {
return (a[0]>b[0]);
}
function OrderHighest1(a, b) {
return (a[0]<b[0]);
}
protected function Fire():void{
var TotalHits:Array = []
var MapHits:Array = []
var NMEHits:Array = []
var FireEquation:Array = CalcSlope(ShotPoint[0],ShotPoint[1],Targ.XPos,Targ.YPos);
var HalfPi:Number = .5*Math.PI
var ROT:Number = this.Rot
var X:Number
var ShootingLeft:Boolean
//Checking if the gun is pointing right or left
if(ROT>=-HalfPi && ROT<HalfPi){
if(GoingLeft){
ShootingLeft = false
} else {
ShootingLeft = false
}
} else {
if(GoingLeft){
ShootingLeft = true
} else {
ShootingLeft = true
}
}
MapHits = this.Parent.CurrMap.HitTest(FireEquation,ShotPoint[0],ShootingLeft)
NMEHits = this.NMEHitTest(FireEquation,ShotPoint[0],ShootingLeft)
//TotalHits = MapHits.concat(NMEHits)
TotalHits = NMEHits.concat(MapHits)
trace("Total1 "+TotalHits)
if(TotalHits.length>0){
if(ShootingLeft){
trace("ShootingLeft")
TotalHits.sort(OrderHighest1)
} else {
trace("ShootingRight")
TotalHits.sort(OrderLowest1)
}
X = TotalHits[0][0]
if(!TotalHits[0][1].LINE){
TotalHits[0][1].Damage(Weapon)
}
} else {
if(ShootingLeft){
X= ShotPoint[0]-5000
} else {
X= ShotPoint[0]+5000
}
}
trace("Total2 "+TotalHits)
var Y:Number = this.GetFormula(FireEquation,X)
Flare.graphics.lineStyle(2, 0xFFD700, 1, false);
Flare.graphics.moveTo(ShotPoint[0], ShotPoint[1]);
Flare.graphics.lineTo(X,Y)
//Flare.graphics.lineTo(X,Y);
this.FlareTime = FLARETIME
this.Reload = RELOAD
}
Output:

Code:
Total1 153.7903559403968,[object Soldier],213.7903559403967,[object Soldier],272.263372184273,[object Soldier],286.8562427380483,[object Line],401.87080684009476,[object Line]
ShootingRight
Total2 272.263372184273,[object Soldier],213.7903559403967,[object Soldier],153.7903559403968,[object Soldier],286.8562427380483,[object Line],401.87080684009476,[object Line]

View Replies !    View Related
Intricate Arrays (sorting Them And That)
Hi, I have a new problem.

I'm now working on the battle system for my game and I'm now officially stuck with the enemy AI. To begin with the system I want to be able to have all information about the enemy ready for use. So my step now is finding the enemy's strongest to weakest attacks from an Array.

Here's what I have.


Code:
enemyAttacks = new Array();

for(kP=0;kP<4;kP++){
enemyAttacks[kP] = new Array();
enemyAttacks[kP]['name'] = _root['enemyAttack'+(kP+1)];
enemyAttacks[kP]['ap'] = _root['enemyAttack'+(kP+1)+'_AP'];
enemyAttacks[kP]['damage'] = _root['attack_'+enemyAttacks[kP]['name']+'Damage'];
}
That all works nicely. But sorting it is kind of tricky, considering that it's a pretty intricate array. I need each of these to contain all the info of the attack (name, ap and damage), except in a way that it's ordered from strongest to weakest (or other way around.. doesn't really matter).

Could someone give me a headstart here. I'm kinda stuck.

View Replies !    View Related
Adding To And Sorting Arrays
Hi!
I'm working on a personal, "for-fun", project, where one will be able to add films to a list of arrays, and these films will be showed in a texxtfield after they have been sorted.

You can download the file here:

The file

Maybe you understand it better if you take a look at the .swf file..


What is supposed to happen is that, when I enter a name a click "Add", I want that movie to be stored in an array (something it is).. After that, the array is to be sorted and then overwrite the previous names that has been added to the list (but not overwriting "__The films in alphabetical order__" string). On top of it all, I want there to be a number to the right og the name, for example: "some_name - 3". This number is which place that name has in the array.

I hope you understand, and that you can help me, because I just can't make this work.
Thanks!

View Replies !    View Related
Sorting Multidimensional Arrays
Hey all,
Iv tried to sort a multidimensional array several times, but it never works.

So far I can place all my data into the Array, and access it, but when it comes to sorting it, it will not actually do the 'sort' part :S

Here's my code:


ActionScript Code:
//Create Array-
var SampleArray:Array = new Array(3);

//Input data into Array-
SampleArray[0] = [200,1];
SampleArray[1] = [10,2];
SampleArray[2] = [2,3];

//Now trace the Array before being sorted-
trace(SampleArray);

//Now Sort the MultiDimensional Array based on 1st value-
SampleArray.sort[Array.NUMERIC]; //Produces Run-Time error

//Now trace the Array after being sorted-
trace(SampleArray); //not executed because of the previous error

The last line of code I have not been able debug. I have tried sortOn as well, but I am not sure on how to use the FeildName thing.

Can anyone help me with this?

View Replies !    View Related
Sorting Arrays Randomly
I have an array, inside each position in that array are objects with properties. How, after I set the array and it's object's properties, do I sort it randomly where there will be a different order everytime? Here's an example of my array:

--------------------------------------------------

LevelArray = new Array();

LevelArray[0] = new Object();
LevelArray[0].name = "Cold Mountain";
LevelArray[0].difficulty = 1;
LevelArray[0].completed = false;

LevelArray[1] = new Object();
LevelArray[1].name = "Death Valley";
LevelArray[1].difficulty = 2;
LevelArray[1].completed = false;

LevelArray[2] = new Object();
LevelArray[2].name = "Cliffhanger";
LevelArray[2].difficulty = 3;
LevelArray[2].completed = false;

--------------------------------------------------

It's a game and I need the levels to be in random order as to which one the user's play. Any help would be appreciated. Thanks.

Selfminded

View Replies !    View Related
Sorting Multidimensional Arrays
I have an array containing random dates, each in its own small array of which the first node is the month and the second the year:
var arr:Array = [
[1,2008],
[2,2009],
[6,2009],
[4,2008],
[4,2008]
];

I am trying to write a sorting function to use with arr.sort() that will use the year AND month nodes to arrange the dates chronologically. Can't get it to work though, anyone have any advice?

Cheers all

View Replies !    View Related
Sorting Associative Arrays
I have two arrays. One contains numbers and the other contains strings. I want to do a

sortOn(DECENDING) for the number array and then have the string array sort to match.

if my string array is

string[0] = "morning";
string[1] = "noon";
string[2] = "night";

number[0] = 3;
number[1] = 1;
number[2] = 2;

i'll sort the number array and that's fine. but can i apply that same sort to the string array?

View Replies !    View Related
Adding To And Sorting Arrays
Hi!
I'm working on a personal, "for-fun", project, where one will be able to add films to a list of arrays, and these films will be showed in a texxtfield after they have been sorted.

You can download the file here:

The file

Maybe you understand it better if you take a look at the .swf file..


What is supposed to happen is that, when I enter a name a click "Add", I want that movie to be stored in an array (something it is).. After that, the array is to be sorted and then overwrite the previous names that has been added to the list (but not overwriting "__The films in alphabetical order__" string). On top of it all, I want there to be a number to the right og the name, for example: "some_name - 3". This number is which place that name has in the array.

I hope you understand, and that you can help me, because I just can't make this work.
Thanks!

View Replies !    View Related
Sorting Parallel Arrays XML Problem.
Ok - here's the problem I have:

I have imported some XML from a database, found the two sets of records I needs (let's say to make it easdy, that they are username and password) and stored them each in an array. Now I want to sort the usernames alphabetically and have the passwords sorted into the same order so that username[4] still relates to password[4], etc.

How is this done? Should I not have sorted them into 2 seperate arrays? Please help - I know it must be possible but cannot work out how.

View Replies !    View Related
Sorting Multi-dimensional Arrays
is it possible to sort multi-dimensional arrays by one of its dimensions? if so, can someone show me an example of how that would be done?

tia

View Replies !    View Related
Sorting MD Arrays Using 2 Criteria Query.
I've found a great tutorial that sorts arrays here

However, I need to sort with 2 or more criteria's.
In Aussie Rules Football (and probably many other sports) the ladder is sorted firstly by Premiership Points, then, as teams can, and usually do, have equal points, the order is determined by a second criteria in this case Percent.

Resolved.. see below.

View Replies !    View Related
Randomly Sorting Arrays Parallel?
how could I randomly sort two different arrays so that both are randomly sorted in the same way?

I can do it for one array:


Code:
function randSort() {
return (Math.round(Math.random())-0.5);
}

cArray.sort(randSort);

//I've already declared cArray, this should be all the code you need to see
but if i use cArray.sort(randSort) and dArray.sort(randSort), both arrays will be separately randomized. so what code will let two arrays receive the same randomization?

View Replies !    View Related
Sorting Multi-dimensional Arrays?
Ok so I know how to sort single arrays but am having trouble sorting multi-dimensional. Do you just set up the sort in the same way!?

Thanks in advance
Corey

View Replies !    View Related
[CS3] Sorting Multiple Arrays With Relationship
Ok, so I have some arrays I'm trying to sort. In reality all the data is coming from xml files, but I'm going to break it down so it's easier to communicate, and get my head around.

Say I've got a couple of arrays that have a direct relationship.

PHP Code:



var id = [15,16,17,18,19]
var score = [21,17,18,24,11];




(The score 21 is actually a property of the 15th item in the xml file, but keeping it simple I'm just making the first array represent its id.)

Now I need to sort the score array, but I need the id array to sort in the same order to keep the relationship between the numbers (so I can later find the right item in the xml file). How might I be able to do this?

View Replies !    View Related
Sorting Multidimensional Arrays/Objects
I have been thinking about this for a while now. I want to be able to sort an array of objects depending on the object index, but, not just one of their indexes.

for example:


Code:
object1 = {streetNum:12, road:'Truro', suburb:'Sandringham', city:'Auckland', price:5000000};
object2 = {streetNum:2, road:'Wayside', suburb:'CBD', city:'Auckland', price:250000};

objectArray = [object1, object2];
As above i need to be able to sort the objectArray by streetNum or road or any combination of indexes.

The objects are being populated from a mysql database using php, would i be better to do it with mysql or php? I would rather do it all in flash so i only have to load the data once then can reshuffle within flash.

Thanks in advance.

View Replies !    View Related
Sorting Arrays From External Variables
I thought I'd better start a new thread as I confused myself with the previous one on this subject.

With a bit of help from tripleaxis I've managed to import an asp file from an Access db into a Flash movie.

I've also managed to sort these variables into an array after loading them into an empty MC on the stage. The debugging window has also assured me that they are there all nice and neat.

The problem is that I need to make a dynamic table to show this array and found the fla from Moock that does the trick perfectly.
The actions for this table naturally, are in Frame 1 of the movie.

I've tried all forms that I know to call this array into the function that generates the table without success. Well, OK, really I only know one and it's not working.

In the tutorial Moock uses an array called "tiles". I'm using an array called "tiles" as well that is present in the empty MC "arraySort". But neither "_root.arraySort.tiles" or "arraySort.tiles" works.

Can anyone help me?
Thanx in advance if you can

View Replies !    View Related
Sorting Numeric Values In Arrays - Question
I've created an array that represents dynamically generated numeric values. My problem is that when I try to sort the array in descending order Flash seems to translate single digit values as double digits. For example, say I have an array of 40, 6, 3, 17...

using myArray.sort();

I get: 17, 3, 40, 6

instead of 3, 6, 17, 40.

Its reading "3" as "30" and "6" as 60 etc.

Any ideas on how I can fix this??


Thanks...

View Replies !    View Related
Sorting An Entire Array Based On The Value In One Of Its Sub-arrays
All the 'sort' tutes I can find either seem to refer to sorting an array by
it's top-level values or by a separate 'comparative' array.

What I need to do is sort an array by one of it's own grandchildren, i.e.
____________________________

Array
----[1]
-------[element1]
-------[element2]
-------[element3]
-------[element4]
----[2]
-------[element1]
-------[element2]
-------[element3]
-------[element4]

..etc etc
____________________________

..where I might want to sort the array by 'element3', for instance.

Any ideas?

Thanks.

View Replies !    View Related
Sorting Arrays Into Numerical And Alpabetical Order
I have a list of numbers wich are associated with a bit of text.
i need to sort these first in numerical order and then if any numbers are the same they then need to be displayed in alpabetical order according to the text assigned to them.
have been srtuggling with this one all day... please help!
thanks

View Replies !    View Related
Sorting Classes (Sorting Algorithms)
I am going to start working on the sorting algorithms found at this site http://www.cs.ubc.ca/spider/harriso...rting-demo.html, the reason for this thread is to ask if anyone would like to help.

Reasons:
there is ALOT of code that needs to be converted to ActionScript 2.0, not only the main class, but each algorithm that extends it, anyway, i'm going to do this, I would just enjoy having help. Thank you in advance.

-Michael

View Replies !    View Related
Sorting Classes (Sorting Algorithms)
I am going to start working on the sorting algorithms found at this site http://www.cs.ubc.ca/spider/harriso...rting-demo.html, the reason for this thread is to ask if anyone would like to help.

Reasons:
there is ALOT of code that needs to be converted to ActionScript 2.0, not only the main class, but each algorithm that extends it, anyway, i'm going to do this, I would just enjoy having help. Thank you in advance.

-Michael

View Replies !    View Related
AES Algorithm
hi ,

has anyone done any flash applications that requires the usage of advanced encryption standard(AES)?

anyone care to share some examples or provide some reading materials?

View Replies !    View Related
Copyright © 2005-08 www.BigResource.com, All rights reserved