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?
FlashKit > Flash Help > Flash ActionScript
Posted on: 10-10-2005, 05:18 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
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.
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
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!
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...
Randomly Sorting A Multidimensional Array
heres the deal ive gotta randomly sort the below multidimensional array. has anyone got a good little prototype to do this...
refGrid = [ ["tile0", "tile1", "tile2", "tile3"],
["tile4", "tile5", "tile6", "tile7"],
["tile8", "tile9", "tile10", "tile11"],
["tile12", "tile13", "tile14", "tile15"] ];
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.
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);
}
}
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!
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?
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
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?
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/
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]
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
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.
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]
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.
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!
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?
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
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?
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!
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
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.
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
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!
[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?
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!
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.
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
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...
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.
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
[F8] Randomly Choose Arrays And Duplicate Movieclip?
I am wondering if someone could please tell me how I could do the following with actionscript: onload of scene randomly choose a category (which is in an array) and match that category with the right subject (which is also in an array). Then duplicate a movieclip to amount of letters in the matched subject? I have been searching Google for the answer however got nowhere. I don't want you to write the whole code for me. All I want is someone to guide me. Thanks in advance.
Randomly Choose Arrays And Duplicate Movieclip?
I am wondering if someone could please tell me how I could do the following with actionscript:
onload of scene randomly choose a category (which is in an array) and match that category with the right subject (which is also in an array). Then duplicate a movieclip to amount of letters in the matched subject? I have been searching Google for the answer however got nowhere. I don't want you to write the whole code for me. All I want is someone to guide me. Thanks in advance.
Parallel Movements
Hi!
Pls help as there is urgent requirement.
Here I'm sending 2 movies file .
main.swf is the sample movie file exactly how my clients wants.
SO I'made abc movie file.
problem I'm facing here is I'm not getting the parallel movements forward and reverse for the buttons slide, on mouse over for products . The first slide i:e The Company goes fine .
TO understand my problem better I'm sending along with abc.fla file too.
Are the slide movements done througn coding or simple tweening? pls let me know.
regards
Sabs
Parallel Port
Is there anyway I can control parallel port with ActionScript in Flash ?? I want to activate some leds via parallel port with Flash.
Thanks.
Parallel Port
Does anyone know how could I control Parallel Port with Flash Mx ??? I want to activate some leds via Parallel Port in Flash.
Thanks.
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
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
Connect With The Parallel Port
hi all, i am trying to make aprograme to send data to the (parallel or serial )port using flash, so how can i do that and what is the code to do that.
thanx alot for ur help
Khader
Parallel Slide Movement
Hi!
Pls help as there is urgent requirement.
Here I'm sending 2 movies file .
main.swf is the sample movie file exactly how my clients wants.
SO I'made abc movie file.
problem I'm facing here is I'm not getting the parallel movements forward and reverse for the buttons slide, on mouse over for products . The first slide i:e The Company goes fine .
TO understand my problem better I'm sending along with abc.fla file too.
Are the slide movements done througn coding or simple tweening? pls let me know.
regards
Sabs
[F8] Values Of 2 Different Objects Parallel Each Other
I have an odd problem. For some reason, when I set the value of one thing, it also seems to set the same value of other things. More specifically, I have an array which contains two objects (let's call them object A and B). When I set, for example, A.customers[3] to 1, B.customers[3] also changes to 1, though it is not supposed to. Here is my code:
Code:
trace("&"+_root.uni["companies"][0].customers[0])
trace("&"+_root.uni["companies"][1].customers[0])
_root.uni["companies"][1].customers[0] = 1;
trace("&"+_root.uni["companies"][0].customers[0])
trace("&"+_root.uni["companies"][1].customers[0])
That outputs this:
&0
&0
&1
&1
Why is my script doing this?
Parallel/symmetrical Shuffle
Hello:
I want to be able to scramble multiple-choice questions for my students so that no two students start with the same question-answers. How can I do this, please?
script follows:
ActionScript:
QuoteAnswerArray = new Array(new Array(
"1. 'Disposition', 'energy level', 'intelligence' and 'interests' were some of the items used in the _______________ .",
"2. In the word 'bewildered', the suffix is _____________ .",
"3. Upon becoming a Seven, Lily received _________________ .",
"4. Lily was __________ sister."
), new Array(
"Ceremony of Naming", "Ceremony of Assignments", "Ceremony of Spouses", "Ceremony of Releasing", "C",
"be-", "-ed", "-ered", "none of the above", "B",
"a back-buttoned jacket", "a front-buttoned jacket", "a zippered jacket", "new hair ribbons", "B",
"Jonas'", "Jona's", "Jonas's", "none of the above", "C"
));
SWFArray = new Array(
);
score = 0;
i = [0][0];
k = [0][0];
quotation = QuoteAnswerArray [0][i] ;
currentURL = SWFArray[i];
loadMovie (currentURL, "_root.SWFLoader");
AnswerA = QuoteAnswerArray[1][k];
AnswerB = QuoteAnswerArray [1][k+1];
AnswerC = QuoteAnswerArray [1][k+2];
AnswerD = QuoteAnswerArray [1][k+3];
stop ();
Parallel File/link
OK, I'm a newby and I'm looking for a little direction.
I'm creating an interactive will have a button that I want to open another swf file at a particular scene. Specifically, I want to have 2 parallel files that have multiple scenes - I want to be able to go to that same scene from the other file and back using a button.
Any direction would be much appreciated!
AS3 Seek Through Parallel Effect
Hello all,
This might be more of a Flex question than purely AS3 so if you think i should post it elsewhere please feel free to redirect this effort.
Im looking into a way to create a "seekable" parallel effect sequence where the user could control the playback of the sequence.
im thinking of a nice scroll bar allowing you to jump to any moment in the parallel effect sequence.
I've looked in the effectInstance classes who have playheadtime properties but i dont think its built for seeking through the effect. Also it appears that you can't really control an effect beyond pausing, resuming or reverse playing?
Here's a quick example that'll help illustrate what im talking about (the code is bogus but it should illustrate what im trying to accomplish here:
Code:
in main.mxml
<mx:Script>
<![CDATA[
import mx.effects.Effect;import mx.effects.WipeDown;import KML.*;import Seq.*;import mx.events.IndexChangedEvent;
publicfunction seekTo():void{//tie this one up to the slider so it seeks to a position in the parallel's execution "timeline".
}
]]>
</mx:Script>
<mx:Parallel id="WipeRightUp">
<mx:WipeRight id="ef_1" startDelay="0" duration="1000" target="{line_1_textBox}"/>
<mx:WipeRight id="ef_2" startDelay="1000" duration="1000" target="{line_2_textBox}"/>
<mx:WipeRight id="ef_3" startDelay="2000" duration="3000" target="{line_3_textBox}"/>
<mx:WipeRight id="ef_4" startDelay="5000" duration="5000" target="{line_4_textBox}"/>
</mx:Parallel>
<mx:Buttonlabel="Start Animation" click="mainViewBox.visible=false;mainViewBox.visible=true;" id="animateButton"/>
<mx:VBox
id="mainViewBox" showEffect="WipeRightUp">
<mx:Label text="First line of text here" width="100%" id="line_1_textBox"/><mx:Label text="Second line of text here" width="100%" id="line_2_textBox" /><mx:Label text="Third line of text here" width="100%" id="line_3_textBox" /><mx:Label text="Fourth line of text here" width="100%" id="line_4_textBox" /></mx:VBox>
<mx:HSlider x="160" y="235" dragExit="seekTo()"/>
Thanks for your time
Hard Parallel Array Dilemma
Hi. I have two arrays as follows
code:
var aone:Array=["153","545","222"]
var atwo:Array=[9,10,13,30,89]
Here's where it gets hard at least for me.I am trying to use the charAt(n) in the first array to set some movie clips to the corresponding point in the second array.I am doing this inside a function.So I hope this makes sense.
code:
mc_one._x= aone[0]aone.charAt(1)[need the corresponding one in atwo so here it be 9];
mc_two.x=[0]aone.charAt(2)[corresponding one in atwo so here it be 89];
mc_three._x=[0]aone.charAt(3)[need the corresponding one in a two so here it be 13]
//all the come from the selected index in first array's chartAt
I know that's some messed up pseudocode and probably confuses the heck out of you but I don't know how else to explain it.
Basically inside the function I am setting the index of the aone array to 0,1 or 2.Then trying to use the charAt(n) of the selected array index to correspond with the values of the index in atwo.
Hope that explains it good enough,and hope someone has the solution.
Cheers
JamesLoacher
|