Sorting A Multidimensional Array By The Date(03.11.04)
Hi,
I need a sort function that will read data from an array and sort it by the date - first to last. The date format is (03.11.01) which seems to make it a bit more complex to sort.
Here is my code for loading data into flash via loadVars:
ActionScript Code: Concert_file = new LoadVars();Concert_fileURL = "http://www.domain.com/concert_data.txt";Concert_file.load(Concert_fileURL);Concert_file.onLoad = function(success) { if (success) { ConcertArray = new Array(); for (i=0; i<this.NUMITEMS; i++) { var cDate = eval("this.cDate"+i); var cVenue = eval("this.cVenue"+i); var cCity = eval("this.cCity"+i); var cWith = eval("this.cWith"+i); var cInfo = eval("this.cInfo"+i); arrayMonth = cDate; arrayMonth = arrayMonth.substr(0, 2); if (arrayMonth != undefined) { ConcertArray[i] = [cInfo, cWith, cCity, cVenue, cDate]; } } }};
This is the txt file loadVars loaded:
ActionScript Code: &cDate7=06.08.04&cVenue7=T Joes&cCity7=Mil, WI&&cDate8=08.13.04&cVenue8=400bar&cCity8=Min, MN&&cDate9=07.08.04&cVenue9=T Joes&cCity9=Mil, WI&
I have tried many things and no real results to show. I get lost at the Multidimensional Array part being loaded from loadVars. I see myself parseing the date out of the array and then run the custom sort, but...
Any ideas would be
Thanks
KirupaForum > Flash > ActionScript 1.0/2.0
Posted on: 03-11-2004, 04:13 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Sorting A Multidimensional Array By The Date(03.11.04)
Hi,
I need a sort function that will read data from an array and sort it by the date - first to last. The date format is (03.11.01) which seems to make it a bit more complex to sort.
Here is my code for loading data into flash via loadVars:
ActionScript Code:
Concert_file = new LoadVars();Concert_fileURL = "http://www.domain.com/concert_data.txt";Concert_file.load(Concert_fileURL);Concert_file.onLoad = function(success) { if (success) { ConcertArray = new Array(); for (i=0; i<this.NUMITEMS; i++) { var cDate = eval("this.cDate"+i); var cVenue = eval("this.cVenue"+i); var cCity = eval("this.cCity"+i); var cWith = eval("this.cWith"+i); var cInfo = eval("this.cInfo"+i); arrayMonth = cDate; arrayMonth = arrayMonth.substr(0, 2); if (arrayMonth != undefined) { ConcertArray[i] = [cInfo, cWith, cCity, cVenue, cDate]; } } }};
This is the txt file loadVars loaded:
ActionScript Code:
&cDate7=06.08.04&cVenue7=T Joes&cCity7=Mil, WI&&cDate8=08.13.04&cVenue8=400bar&cCity8=Min, MN&&cDate9=07.08.04&cVenue9=T Joes&cCity9=Mil, WI&
I have tried many things and no real results to show. I get lost at the Multidimensional Array part being loaded from loadVars. I see myself parseing the date out of the array and then run the custom sort, but...
Any ideas would be
Thanks
[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.
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
Sorting Multidimensional Array
I searched to forum and could not find the information I need. I am trying to sort my multidimensional array by its index position in the array.
Here is my array:
ActionScript Code:
var navArray:Array = new Array(["josh", "file0.swf"], ["joshua studios", "file1.swf"], ["design", "file2.swf"], ["flash eight", "file3.swf"]);
Sorting Multidimensional Array
hi guys,
how can i sort for example this multidimensional array ?
var matriz = [["Andrea",2],["Osasha",1],["Giraldo",3]];
matriz[1].sort(Array.DESCENDING);
trace(matriz)
where in this case the number is the position of the name !
thx for any guidance !
Sorting Multidimensional Numeric Array In MX
I need some help on how to sort an array with nested arrays of matched numbers: one nested array holds x-coordinates and the other nested array holds y-coordinates. The position of each x,y pair is matched, so if I use a typical numerical sorting function, I succeed only in sorting one array or the other, and I undo the relationship.
I describe my arrays below with example x,y coords, and although I may be heading in the wrong direction, I included the function that I know works to sort either one or the other array:
[as]
mySort = function(a,b) {
return a-b;
}
var x= new Array(12,21,-13,48,33);
var y= new Array(6, -99, 7, -2, -2);
var xy = new Array(x,y)
xy.sort(mySort);
//output: -13,12,21,33,48,6,-99,7,-2,-2;
//(only first nested array of xy sorts, so nested arrays lose their relationship)
I need to output: -13,12,21,33,48,7,6,-99,-2,-2
/[as]
The arrays don't have to be nested. I would be happy to be able to sort the x array and have the y array be sorted by the x array.
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 An Array Of Date Objects
I need to sort an array of Flash Date
Objects. I have an array that contains several dates, but they may not be in chronological order...
I need those dates to be sorted and put into chronological order every time a new date is added to the array.
I can't think of a good way to do it, and I also know it is going to take me like 4 pages of code to get that to work.
If anyone has anything already written, or would like to help me, I would really appreciate it.
Thanks!
Sorting An Array In Date Order
Hi,
I have an array that I have populated with various items one of which is a date. I am then displaying these values on screen in columns and rows. I have added an arrow at the top of each column wich allows you to sort it asending and desending.
I'm having a problem sorting via the date columns though (All others are fine). It seems to be sorting the date alphabetically even though its a proper date object I'm storing in the array.
Here's the result I get if I sort my array on my date field:
Fri Sep 26 10:02:32 GMT+0100 2003
Thu Oct 27 10:02:32 GMT+0100 2005
Mon Sep 27 10:02:32 GMT+0100 2004
Fri Aug 1 10:02:32 GMT+0100 2003
Mon Mar 2 10:02:32 GMT+0000 2009
As you can see its sorted alphabetically and not in date order. I'm using the sortOn class to sort the array like this:
ActionScript Code:
data_array.sortOn(["startDate"], 0);
Maybe its not possible to sort an array based on actual date values rather than the string value but that seems a bit odd.
Can anyone help?
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 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 Data According To Date
Hey all, is there any efficient method in sorting data according to a birthdates a user submit?
In my case, I got to sort my user into 12 different group, depending on the birthdates they submit, the group and date is as follow.
Group 1February 18, 2007 - February 6, 2008
Group 2January 29, 2006 - February 17, 2007
Group 3February 9, 2005 - January 28, 2006
Group 4January 22, 2004 - February 8, 2005
Group 5February 1, 2003 - January 21, 2004
Group 6February 12, 2002 - January 31, 2003
Group 7January 24, 2001 - February 11, 2002
Group 8February 5, 2000 - January 23, 2001
Group 9February 16, 1999 - February 4, 2000
Group 10January 28, 1998 - February 15, 1999
Group 11February 7, 1997 - January 27, 1998
Group 12February 19, 1996 - February 6, 1997
Group 1February 10, 1994 - January 30, 1995
Group 2January 23, 1993 - February 9, 1994
Group 3February 4, 1992 - January 22, 1993
Group 4February 15, 1991 - February 3, 1992
Group 5January 27, 1990 - February 14, 1991
Group 6February 6, 1989 - January 26, 1990
Group 7February 17, 1988 - February 5, 1989
Group 8January 29, 1987 - February 16, 1988
Group 9February 9, 1986 - January 28, 1987
Group 10January 20, 1985 - February 8, 1986
Group 11February 2, 1984 - January 19, 1985
Group 12February 13, 1983 - February 1, 1984
Here is only 2 chuck of table for a reference, in the mini program I¡¯m creating there is going to be 5 similar table like this.
So my question is, anyway when the user enter their birth day month and years, it will auto direct them to the group they belong to?
Thanks
Sorting Data According To Date
Hey all, is there any efficient method in sorting data according to a birthdates a user submit?
In my case, I got to sort my user into 12 different group, depending on the birthdates they submit, the group and date is as follow.
Group 1February 18, 2007 - February 6, 2008
Group 2January 29, 2006 - February 17, 2007
Group 3February 9, 2005 - January 28, 2006
Group 4January 22, 2004 - February 8, 2005
Group 5February 1, 2003 - January 21, 2004
Group 6February 12, 2002 - January 31, 2003
Group 7January 24, 2001 - February 11, 2002
Group 8February 5, 2000 - January 23, 2001
Group 9February 16, 1999 - February 4, 2000
Group 10January 28, 1998 - February 15, 1999
Group 11February 7, 1997 - January 27, 1998
Group 12February 19, 1996 - February 6, 1997
Group 1February 10, 1994 - January 30, 1995
Group 2January 23, 1993 - February 9, 1994
Group 3February 4, 1992 - January 22, 1993
Group 4February 15, 1991 - February 3, 1992
Group 5January 27, 1990 - February 14, 1991
Group 6February 6, 1989 - January 26, 1990
Group 7February 17, 1988 - February 5, 1989
Group 8January 29, 1987 - February 16, 1988
Group 9February 9, 1986 - January 28, 1987
Group 10January 20, 1985 - February 8, 1986
Group 11February 2, 1984 - January 19, 1985
Group 12February 13, 1983 - February 1, 1984
Here is only 2 chuck of table for a reference, in the mini program I’m creating there is going to be 5 similar table like this.
So my question is, anyway when the user enter their birth day month and years, it will auto direct them to the group they belong to?
Thanks
Sorting Data According To Date
Hey all, is there any efficient method in sorting data according to a birthdates a user submit?
In my case, I got to sort my user into 12 different group, depending on the birthdates they submit, the group and date is as follow.
Group 1February 18, 2007 - February 6, 2008
Group 2January 29, 2006 - February 17, 2007
Group 3February 9, 2005 - January 28, 2006
Group 4January 22, 2004 - February 8, 2005
Group 5February 1, 2003 - January 21, 2004
Group 6February 12, 2002 - January 31, 2003
Group 7January 24, 2001 - February 11, 2002
Group 8February 5, 2000 - January 23, 2001
Group 9February 16, 1999 - February 4, 2000
Group 10January 28, 1998 - February 15, 1999
Group 11February 7, 1997 - January 27, 1998
Group 12February 19, 1996 - February 6, 1997
Group 1February 10, 1994 - January 30, 1995
Group 2January 23, 1993 - February 9, 1994
Group 3February 4, 1992 - January 22, 1993
Group 4February 15, 1991 - February 3, 1992
Group 5January 27, 1990 - February 14, 1991
Group 6February 6, 1989 - January 26, 1990
Group 7February 17, 1988 - February 5, 1989
Group 8January 29, 1987 - February 16, 1988
Group 9February 9, 1986 - January 28, 1987
Group 10January 20, 1985 - February 8, 1986
Group 11February 2, 1984 - January 19, 1985
Group 12February 13, 1983 - February 1, 1984
Here is only 2 chuck of table for a reference, in the mini program I’m creating there is going to be 5 similar table like this.
So my question is, anyway when the user enter their birth day month and years, it will auto direct them to the group they belong to?
Thanks
Sorting Data According To Date
Hey all, is there any efficient method in sorting data according to a birthdates a user submit?
In my case, I got to sort my user into 12 different group, depending on the birthdates they submit, the group and date is as follow.
Group 1February 18, 2007 - February 6, 2008
Group 2January 29, 2006 - February 17, 2007
Group 3February 9, 2005 - January 28, 2006
Group 4January 22, 2004 - February 8, 2005
Group 5February 1, 2003 - January 21, 2004
Group 6February 12, 2002 - January 31, 2003
Group 7January 24, 2001 - February 11, 2002
Group 8February 5, 2000 - January 23, 2001
Group 9February 16, 1999 - February 4, 2000
Group 10January 28, 1998 - February 15, 1999
Group 11February 7, 1997 - January 27, 1998
Group 12February 19, 1996 - February 6, 1997
Group 1February 10, 1994 - January 30, 1995
Group 2January 23, 1993 - February 9, 1994
Group 3February 4, 1992 - January 22, 1993
Group 4February 15, 1991 - February 3, 1992
Group 5January 27, 1990 - February 14, 1991
Group 6February 6, 1989 - January 26, 1990
Group 7February 17, 1988 - February 5, 1989
Group 8January 29, 1987 - February 16, 1988
Group 9February 9, 1986 - January 28, 1987
Group 10January 20, 1985 - February 8, 1986
Group 11February 2, 1984 - January 19, 1985
Group 12February 13, 1983 - February 1, 1984
Here is only 2 chuck of table for a reference, in the mini program I’m creating there is going to be 5 similar table like this.
So my question is, anyway when the user enter their birth day month and years, it will auto direct them to the group they belong to?
Thanks
Sorting Datagrid By Date Column
I've got a datagrid with a couple columns with dates (in DD/MM/YYYY string format) that I'd like the user to be able to sort on by clicking the column headers. Unfortunately, Flash treats the data as numbers and puts 01/01/2000 before 02/02/1900.
I've added a headerRelease listener to my datagrid that fires when the user clicks the column header. I've written a custom sort function called SortOnDate which I know works. I put the sort command into the headerRelease function as dataProvider.sort(SortOnDate).
If I trace the dataProvider, the data IS CORRECT. However, the data in the datagrid is still sorted incorrectly.
I'm assuming what's going on is the correctly sorted data goes into the datagrid, but the datagrid still applies the incorrect sorting to the data when it tries to display it since the column header is selected. Any solutions to this?
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.
Comparing Between An Array And A Multidimensional Array
Hi all, this is my first post.
I have only been working with flash for a couple of years, but I know my way around it pretty well. I usually can find answers to any problems I have through searching, but I seem to be stuck on this one....
I am trying to compare an element in an array to an element in an multidimensional array. Here is my code
var songArray:Array = new Array([["q"],["l8"],["l6"]],[["r"]],[["q"],["s5"]]);
var lineArray:Array = new Array("l8","s8","l9","s9");
var tempLine = lineArray[0];
var tempNote = songArray[0][1];
trace(tempLine) // l8
trace(tempNote) // l8
if(tempLine == tempNote) {
trace("True");
} else {
trace("False");
} // False
Why is this?
I appriciate anyones input
Thanks
builder
Flat Array Vs Multidimensional Array
For a game I'm making I've tried to stick with using flat arrays as much as possible because I read somewhere that its faster than using multidimensional arrays. I just need to know if anyone knows or can point me to any place which discusses the speed difference (if there is any).
Using multidimensional arrays would make my coding much easier but if its slower than flat arrays I'm willing to persevere for the better execution time.
Any thoughts?
Multidimensional Array
I am creating a tile-based game, and need large 2D arrays to map out the territory. As it is a large area, and I want to be able to add large objects, I thought that a map function would be good:
map=new Array();
//
Movieclip.createMap= function(beginCol,beginRow,endCol,endRow) {
for(var i=beginCol;i<endCol;i+=1)
for (var j=beginRow;j<endRow;j+=1) {
_root.map[i][j]=1;
}
}
//
Using this I should be able to map out any rectangular area.
The problem is that the map array is only 1 dimension, it doesnt accept the [i][j] parameters. And as it will be a 50*50 tile game, i dont want to declare
map[1]=new Array();
map[2]=new Array(); etc etc
Any ideas on how to declare an empty multidimensional array?
Multidimensional Array
hi I am trying to figure out multidimensional arrays...
I need an array to hold an answer + divider + score...
This is my code....
The dividers are there so I can use them to split the string in authorware
[code]
question = new Array(answer,divider,score);
question[1] = ["apples", " | ", 1];
question[2] = ["bananas", " | ", 1];
trace(question);
outputscore = question.join(" || ");
trace(outputscore);
Is this right?
Also how can I access the answer value of say question [1] ?
can I use question[1].answer = "peaches" ?
any help greatly appreciated!
XML->Multidimensional Array
Hello,
I am trying to put an XML file into a three dimensional array.I have searched this forum for help, but ít didn't help me. Can anyone tell me what's wrong with this function?
xmlRails.onLoad = function(succes){
var i,j,k;
var rails = new Array();
xmlRails = xmlRails.firstChild;
for(i=0;i<xmlRails.firstChild.childNodes.length;i+ +)
{
xmlRails[i] = new Array();
for(j=0;j<xmlrails.firstChild.childNodes[i].childNodes.length;j++)
{
xmlRails[i][j] = new Array();
for(k=0;k<xmlRails.firstChild.childNodes[i].childNodes
[j].childNodes.length;k++)
{
trace(xmlRails.firstChild.childNodes[i].childNodes
[j].childNodes[k]);
rails[i][j][k]=xmlRails.firstChild.childNodes[i].childNodes
[j].childNodes[k];
trace(rails[i][j][k]);
}
}
}
}
I can look into the XML file, but the trace on the array turns up 'undefined'.
Help? PLease? Any help? I'm desperate!
Multidimensional Array
Hi,
I'm strugling for hours now on a multidimensional array.
I load an XML-file and put the data in three array's.
The arPicture array should be multidimensional. In the XML-format i've got
<part>
<text>Blablabla</text>
<hulp>some text</hulp>
<pictures><picture>blabla.gif</picture><picture>blablabla.gif</picture></pictures>
</part>
As you can see there can be more than one pictures in a <part>-tag.
In the code below I've tried to loop trough all the XML-nodes. When a <pictures>-node is found, it loops a second to find all the pictures.
So the result should be:
arPicture[0][0] = blabla.gif
arPicture[0][1] = blablabla.gif
That works fine, until there's a new loop through the first level (<part>-node)
for some reason any value in the arPicture[0][x] is lost, and returns "undefined". The arPicture[1][x] is ok then.
I can't figure why?
Can anyone help? (quite urgent...)
Thanks in advance...
.NET Freak
Code:
var arText = new Array();
var arHelp = new Array();
var arPicture = new Array();
var xmlParser:XML = new XML();
xmlParser.ignoreWhite = true;
xmlParser.load("xml/isvBrugge.xml");
xmlParser.onLoad = function(success:Boolean) {
if (success) {
Title.text = xmlParser.firstChild.firstChild.firstChild.firstChild.nodeValue;
if (xmlParser.firstChild.firstChild.hasChildNodes()) {
i = 0;
x = 0;
for (var aPart = xmlParser.firstChild.firstChild.firstChild; aPart != null; aPart=aPart.nextSibling) {
if (aPart.hasChildNodes()) {
for (var aNode = aPart.firstChild; aNode != null; aNode=aNode.nextSibling) {
if (aNode.nodeName == "Text") {
arText[i] = aNode.firstChild.nodeValue;
}
if (aNode.nodeName == "Hulp") {
arHelp[i] = aNode.firstChild.nodeValue;
}
if (aNode.nodeName == "Pictures") {
x = 0;
for (var aPic = aNode.firstChild; aPic != null; aPic=aPic.nextSibling) {
arPicture[i] = new Array();
arPicture[i][x] = aPic.firstChild.nodeValue;
x++;
}
trace(arPicture);
}
}
i++;
}
x++;
}
}
_root.DelayController.play();
} else {
Title.text = "Loading XML-file";
}
};
Multidimensional Array
This is something not getting right
ar=new Array();
ar[8,0]=1;
ar[5,3]=8;
for(i=0;i<9;i++){
trace(ar[i,0]+" "+ar[i,1]+" "+ar[i,2]+" "+ar[i,3])
}
is delivering the results
1 undefined undefined 8
1 undefined undefined 8
1 undefined undefined 8
1 undefined undefined 8
1 undefined undefined 8
1 undefined undefined 8
1 undefined undefined 8
1 undefined undefined 8
1 undefined undefined 8
But i think it should go like
undefined undefined undefined undefined
undefined undefined undefined undefined
undefined undefined undefined undefined
undefined undefined undefined 8
undefined undefined undefined undefined
undefined undefined undefined undefined
undefined undefined undefined undefined
undefined undefined undefined undefined
1 undefined undefined undefined
Plz help. I think i doesn't know flash.
Multidimensional Array?
basically I have an array of numerical values that change depending on which button is pressed, and they need to be displayed as text but sorted numerically... I thought a multidimensional array would work, but I cant get it to sort right. Is this possible to do, or is there another way to accomplish this thats relatively easy?
The idea is for totals_array to calculate the total value and sort it numerically then name_array replaces that value with the appropriate title and is traced.
button code:
Quote:
on(press) {
// arrays are all created at frame 1 then used on button presses
totals_array[0] = fcsg_array[0] + nutrition_array[0];
totals_array[1] = fcsg_array[1] + nutrition_array[1];
name_array[0] = "Colorado Springs";
name_array[1] = "Minneapolis";
totals_array.sort(Array.NUMERIC);
trace(totals_array);
I am using FL8 also
Any help is appreciated!
Thanks
Multidimensional Array Help
Hi
I have an array with 12 elements
mates =["6", "bob", "4", "10", "fred", "1", "7", "joe", "3", "14", "mark", "7"];
I am trying to convert this into a mutidimensional array
so the new array would look like
newArray=[6,bob,4],[10,fred,1],[7,joe,3],[14,mark,7]
I need to be able to spilt the original array into 4 parts of 3 and then sort the array into order based on the first element.
the final structure in order would look like
[6,bob,4], [7,joe,3],[10,fred,1],[14,mark,7]
I am not sure how to do this can anyone please help?
Help With Multidimensional Array
I am having a problem with creating and loading data into a multidimensional array. I want to create an array to hold data from blog entries in a database. Each array in the larger array will hold the data for each column in the database.
I have tested and the data is coming into Flash fine and is in the LoadVars variable. However the final trace statement in the loop that is loading the data in the array shows "undefined" for the array element.
What am I missing? (code is below)
var blogItems:Array = new Array("artID","artTitle","artDate","artLoc","artCa t","art");
// get blog list data into an array we can use elsewhere
var records:Number = this["records"];
var i:Number;
blogItems["artID"] = new Array();
blogItems["artTitle"]= new Array();
blogItems["artDate"]= new Array();
blogItems["artLoc"]= new Array();
blogItems["artCat"]= new Array();
blogItems["art"]= new Array();
for (i=0; i < records; i++) {
blogItems["artID"][i] = this["artID"+i];
blogItems["artTitle"][i] = this["artTitle"+i];
blogItems["artDate"][i] = this["artDate"+i];
blogItems["artLoc"][i] = this["artLoc"+i];
blogItems["artCat"][i] = this["artCat"+i];
blogItems["art"][i] = this["art"+i];
trace (blogItems["artID"][i]);
}
Multidimensional Array
Hi!
My first post here
i have a problem. I need to pharse xml data and put it in an multidimensional array like this:
slides->slide[0]->subSlides[0]->slideHeader, slideText
slides->slide[0]->subSlides[1]->slideHeader, slideText
slides->slide[0]->subSlides[2]->slideHeader, slideText
slides->slide[1]->subSlides[0]->slideHeader, slideText
slides->slide[1]->subSlides[1]->slideHeader, slideText
slides->slide[1]->subSlides[2]->slideHeader, slideText
And so forth...
and the xml looks like this:
<channel>
<slides>
<slide>
<subSlides>
<slideHeader>Header</slideHeader>
<slideText>Text</slideText>
</subslides>
<subSlides>
<slideHeader>Header</slideHeader>
<slideText>Text</slideText>
</subslides>
<subSlides>
<slideHeader>Header</slideHeader>
<slideText>Text</slideText>
</subslides>
</slide>
<slide>
<subSlides>
<slideHeader>Header</slideHeader>
<slideText>Text</slideText>
</subslides>
<subSlides>
<slideHeader>Header</slideHeader>
<slideText>Text</slideText>
</subslides>
<subSlides>
<slideHeader>Header</slideHeader>
<slideText>Text</slideText>
</subslides>
</slide>
</slides>
Anyone that knows a solution?
I've made a whole bunch of tries but always end up with a error (#1010 or something like that).
Thanx!
//Martin
Multidimensional(3d) Array
ok, trying to make a multidimensional array that holds: questions, answers, and which answer is correct. all this info is stored in an external XML file that contains other text as well.
right now i have this:
var allReview:XMLList = theCaption.review.question.text();
var allAnswers:XMLList = theCaption.review.question.answer.text();
var allCorrectAnswers:XMLList = theCaption.review.question.answer.attributes();
trace("review questions: " + allReview);//traces out all the questions
trace("review questions: " + allReview[0]);//traces 1st question
now i believe i will make the correct answer a boolean value in a attribute in the XML file.
keep in mind some questions will have 2 answers and some will have 4.
one column for questions, one for answers, and one for boolean values.
how do i go about storing all this info in a multidimensional array???? if there's 4 answers to on question- there's no point in storing the question 4 times.
Please some type of direction on this issue would be great!!!
Multidimensional Array Help
hey people,
i am trying to create a dynamic menu with a submenu. i simply setted up a xml file which is looking like that:
ActionScript Code:
<menu>
<item pos = "main" type = "movie" cat = "none" sub = "no">
<title>news</title>
<content>news.swf</content>
</item>
<item pos = "main" type = "movie" cat = "none" sub = "no">
<title>projects</title>
<content>pr.swf</content>
</item>
<item pos = "main" type = "button" cat="none" sub = "yes">
<title>office</title>
<content></content>
</item>
<item pos = "sub" type = "text" cat="büro" sub = "no">
<title>bio</title>
<content><![CDATA[Here some text for content]]></content>
</item>
<item pos = "sub" type = "text" cat="büro" sub = "no">
<title>qualification</title>
<content><![CDATA[Here some more text]]></content>
</item>
<item pos = "sub" type = "text" cat="büro" sub = "no">
<title>internships</title>
<content><![CDATA[Bla bla]]></content>
</item>
<item pos = "main" type = "button" cat="none" sub = "yes">
<title>press</title>
<content></content>
</item>
<item pos = "sub" type = "text" cat="presse" sub = "no">
<title>won prizes</title>
<content><![CDATA[...]]></content>
</item>
<item pos = "sub" type = "movie" cat="presse" sub = "no">
<title>publication</title>
<content>p.swf</content>
</item>
<item pos = "sub" type = "text" cat="presse" sub = "no">
<title>exhibitions</title>
<content><![CDATA[More text]]></content>
</item>
<item pos = "sub" type = "movie" cat="presse" sub = "no">
<title>interviews</title>
<content>int.swf</content>
</item>
<item pos = "main" type = "movie" cat="none" sub = "no">
<title>contact</title>
<content>contact</content>
</item>
<item pos = "main" type = "text" cat="none" sub = "no">
<title>copyrights</title>
<content><![CDATA[sdf]]></content>
</item>
</menu>
now i had following idea:
i wanted to sort the nodes by asking for the position in the menu and if they have a sub menu (attributes pos & sub).
so i wrote a function which is looking like that:
ActionScript Code:
function sortButtons(bLabel:String, bType:String, bPos:String, bCat:String, bID:Number, bSub:String):Array {
var menu:Array = new Array(new Array(), new Array());
var bString = bLabel+"|"+bType+"|"+bPos+"|"+bCat+"|"+bID;
if(bSub == "no" && bPos == "main"){
counterSub = 0;
trace("menu["+counter+"]["+counterSub+"] pushed "+bString+" ("+bSub+", "+bPos+")");
menu[counter] = bString;
counter++;
}
else if(bSub == "no" && bPos == "sub"){
counterSub++;
trace("menu["+(counter-1)+"]["+counterSub+"] pushed "+bString+" ("+bSub+", "+bPos+")");
menu[(counter-1)][counterSub] = bString;
}
else if(bSub == "yes" && bPos == "main"){
counterSub = 0;
trace("menu["+counter+"]["+counterSub+"] pushed "+bString+" ("+bSub+", "+bPos+")");
menu[counter] = bString;
counter++;
}
else {
counterSub = 0;
trace("menu["+counter+"]["+counterSub+"] pushed "+bString+" ("+bSub+", "+bPos+")");
menu[(counter-1)][counterSub] = bString;
counterSub++;
}
trace(menu);
return menu;
}
the trace("menu["+counter+"]["+counterSub+"] pushed "+bString+" ("+bSub+", "+bPos+")"); is outputting the menu array totally right. but when i'm tracing menu at the end of the function it is stuck at the second button. do you have an idea, how this could be realized?
oh and by the way: the function is called in the onLoad function in a simple for-loop:
ActionScript Code:
for(i = 0; i < nodesNumber; i++){
var labels:String = String(nodes[i].childNodes[0].firstChild.nodeValue);
var type:String = String(nodes[i].attributes.type);
var pos:String = String(nodes[i].attributes.pos);
var cat:String = String(nodes[i].attributes.cat);
var subMenu:String = String(nodes[i].attributes.sub);
buttons = sortButtons(labels, type, pos, cat, i, subMenu)
}
i really appreciate your help!
thanks a lot!
MultiDimensional Array
I am trying to create an array that holds some info for each item in the array how would I do that?
I want to add a two variables to an array that are essentialy one item in the array. Also how would I acess them later?
a= 1;
b = 2;
myArray = [];
myArray.push [??? this is were I confused with the syntax.
I would really appreciate the help.
Thanks
Multidimensional Array
Hi, i have some problem witha multidimensional array.
Now explain:
I've create a structure like a Table, the data are take from a bidimensional array. I want include some button to order by a column for example order by code, name etc.
For ordering array i use sortOn() command but the result is anomalous, some time there is a change between 2 column and other time the array is the same in the same order.
Someone can help me please.
P.S. Sorry for my english, i hope to be right.
Nice
Multidimensional Array
how do i create an array of 30x30 elements? i have tried
Code:
p = [[0],[0]];
but it doesn't seem to work.. please help me ASAP
Multidimensional Array
I have an array/Object:
Code:
[0] = mm_name=image1.jpg,mm_path=img/req1,mm_keywords=keyword1
[1] = mm_name=image2.jpg,mm_path=img/req9,mm_keywords=my black cat
[2] = mm_name=image3.jpg,mm_path=img/req7/new,mm_keywords=a brown dog
I want to convert it to a multidimensional array (i think?) so I can reference, like so:
Code:
trace(myArray[1]["mm_name"]); // image2.jpg
trace(myArray[2]["mm_keywords"]); //a brown dog
Any suggestions are greatly appreciated!
XML To Multidimensional Array
Hi There,
First of all thanks for reading this.
I'm trying to build a trivia slideshow similar to what you would see at the movie theater. I can populate two arrays, one for questions and one for answers. But in order to randomize the output of the question/answers (making sure that the right answers stay with the right questions) I am trying to put them into a multidimensional array. Then later I'll pull a random from that to get my output for my sprite.
So my xml looks like this:
Code:
<trivia>
<entry question="How do you feel?" answer="I feel Fine"/>
<entry question="Are you tall?" answer="I am tall"/>
<entry question="Are you sleeping?" answer="I am asleep"/>
</trivia>
and my actionscript looks like this:
Code:
var xml:XML = new XML(); //setup initial vars to retreive xml data
var loader:URLLoader = new URLLoader();
loader.load(new URLRequest("trivia.xml")); //xml file is local to swf
loader.addEventListener
(Event.COMPLETE,function(evt:Event):void //wait for xml to load
{ xml = XML(evt.target.data);
var num:Number = xml.entry.length();
trace(num);
trace(xml);
var trivquest:Array = new Array();
var trivanswer:Array = new Array();
for (var i:Number = 0; i < num; i++)
{
trivquest[i] = xml.entry.@question[i].toXMLString();
trivanswer[i] = xml.entry.@answer[i].toXMLString();
}
var trivlist:Array = new Array((trivquest[i]),(trivanswer[i]));
trace(trivlist);
}
);
So my multiDarray is trivlist, but it's not getting populated properly.
Any advice/help is greatly appreciated!
Tony
Multidimensional Array
Hi, i have some problem witha multidimensional array.
Now explain:
I've create a structure like a Table, the data are take from a bidimensional array. I want include some button to order by a column for example order by code, name etc.
For ordering array i use sortOn() command but the result is anomalous, some time there is a change between 2 column and other time the array is the same in the same order.
Someone can help me please.
P.S. Sorry for my english, i hope to be right.
Nice
Multidimensional Array
how do i create an array of 30x30 elements? i have tried
Code:
p = [[0],[0]];
but it doesn't seem to work.. please help me ASAP
Multidimensional Array On The Fly
I'm going a bit...crazy...with this problem.
I need to create a multi-dim array that keeps track of movieclip references and under each movieclip references, more references to other clips.
So lets start with the first level movieclips:
mArray = [mc1, mc2, mc2, mc4, mc5];
and lets add a couple other references under it:
mArray[mc1] = [mc6, mc7];
mArray[mc2] = [mc8, mc9];
mArray[mc3] = [mc10, mc11];
I'll never be assigning these on first instance, I need to be able to push new references into the arrays as I go.
After this I'll need to be determine the clips related to each movieclip. So if I want to determine clips under mc2 I want to do:
mArray[mc2].length and recursively scan through it's children and command them as I would like.
I'm not sure if this is possible but it would make my life a "heck" of a lot easier. so my question is how do I add children to each array reference as I go?
thanks in advance.
Multidimensional Array
Hello!
I't trying to create a multidimensional array of the following kind:
let's say we have a list of cities:
Rome, Paris, London
and a list of neighborhoods for each(i.e: rn1,rn2,...for Rome)
How can I create one array that holds all that information like:
var travel = new Array()
//and the travel array hold information like:
Rome(rn1,rn2,rn3),Paris(pn1,pn2),London(ln1,ln2,ln3,ln4)
so later I could access travel[0] = Rome, travel[1] = Paris
and...
travel[0][0] = rn1
travel[1][1] = pn2
or something like it...
thanks!
Multidimensional Array Problem
Hi there,
I am putting together a very large ROI calcualtor for a client. It has an input screen, an output screen and a whole spreadsheet full of variables to calculate everything up with.
Since there is such a huge amount of 'assumtion' variables to work with I've decided to putthem all into a mutidimesional array and call them up that way (ie: Assumptions[2][1]). My problem comes in when i build my second mutidimensional array using a combination of input values and values from the first array.
I found out that i can't call an array item when i'm trying to build an array because of the brackets "[" i think.
Here's what it looks like:
array2 = [ [((e14 + ((array[0][0])*e14))* 40 * 52),((e14+(array1[0][1]*e14))*40*52),((e14+(array1[0][2]*e14))*40*52)],
[moredata,moredata,moredata] ];
Does anyone know a workaround for this?
I tried the old JavaScript infront of the [ and ] to show that i'm not trying to start or end an array but that doesn't work in Actionscript.
Does this make any sense?
Thanks for any help you can give me.
[MX] Populating A Multidimensional Array
I am relatively new to Flash MX. While I've done a pretty good job
in the last two days manipulating XML files and arrays, the following
challenge finally has my head spinning. Could anyone help me out? I've managed to work the XML file okay, but going nuts with the array itself.
I have the following XML file structure to work with, and need to
bring it into a multidimensional array so that I can read it often
to populate UI components dynamically.
XML File "productlist.xml" has the following structure.
(use of square brackets instead of angle brackets to allow display in this forum only)...
----------------------------------------------------------------
[?xml version="1.0"?]
[products]
[item]
[name]Product Name[/name]
[desc]Product Description Here[/desc]
[image]image.jpg[/image]
[price]xxx.xx[/price]
[option]
[optname]Option Name[/optname]
[optdesc]Option Description here[/optdesc]
[optimage]optimage.jpg[/optimage]
[optprice]zzz.zz[/optprice]
[/option]
[/item]
[/products]
---------------------------------------------------------------
Of course the structure will include many items. Some items
will have NO options, while others may have ten options.
All other elements are fixed.
I believe a four-dimensional array is needed. Might be wrong.
A diagram of how I am intending to access the array appears below:
//-------------- MY IMAGINED ARRAY STRUCTURE -----------------------//
// products[x] -- (a specific product)
// products[x][0] -- (product x name)
// products[x][1] -- (product x desc)
// products[x][2] -- (product x image)
// products[x][3] -- (product x price)
// products[x][4] -- (product options array)
// products[x][4][y] -- (product x option y)
// products[x][4][y][0] -- (product x option y name)
// products[x][4][y][1] -- (product x option y desc)
// products[x][4][y][2] -- (product x option y image)
// products[x][4][y][3] -- (product x option y price)
//-----------------------------------------------------------------//
I have a good chunk of code working already, but I seem to be
having trouble over-writing sections of the array while reading
through the XML file.
I think I remember seeing someone else with a similar problem. When I trace in the middle of iterating through the file, the array seems to be populating correctly. But when I trace again after the looping is complete, the entire array is filled with the elements from the last major node of the XML file.
Could someone help me out with code for this? I've been researching and fiddling all day to no end.
Visious Multidimensional Array...
Hi
I never use multi dimensional arrays before, but for a project Im doing I would like to combine a bunch of arrays into one ...
First I load some strings from txt for testing purpose..
the txt.:
Code:
&dato=01-01-2005,10-01-2005
&juliansk=1,10
&navn=fest1,fest2
&antal=10,23
Ok.. now I load, split and TRY.. to combine these.. but the trace at the bottom is empty or undefined..
Code:
my_date = new Date();
year = my_date.getFullYear();
all_years = new LoadVars();
all_years.load("data.txt");
all_years.onLoad = function(success) {
if (success) {
dato = this.dato.split(",");
jul = this.juliansk.split(",");
navn = this.navn.split(",");
antal = this.antal.split(",");
size = antal.length;
opdelArray(dato, jul, navn, antal, size);
} else {
trace("Det bare noget lort!");
}
};
stop();
function opdelArray(dato, juliansk, navn, antal, size) {
my_date = new Date();
year = my_date.getFullYear();
var j = 0;
var k = 0;
fest_data = new Array(size);
fest_data[0] = year;
for (var i = 0; i<size; i++) {
temp = dato[i].split("-");
trace(temp[2]);
if (fest_data[j] == temp[2]) {
fest_data[j][k] = ""+dato[i];
fest_data[j][k].push(new Array(1));
fest_data[j][k][0] = ""+juliansk[i];
fest_data[j][k][0].push(new Array(1));
fest_data[j][k][0][0] = ""+navn[i];
fest_data[j][k][0][0].push(new Array(1));
fest_data[j][k][0][0][0] = ""+antal[i];
k++;
} else {
j++;
k = 0;
fest_data[j] = ""+temp[2];
fest_data[j].push(new Array(size));
fest_data[j][k] = ""+dato[i];
fest_data[j][k].push(new Array(1));
fest_data[j][k][0] = ""+juliansk[i];
fest_data[j][k][0].push(new Array(1));
fest_data[j][k][0][0] = ""+navn[i];
fest_data[j][k][0][0].push(new Array(1));
fest_data[j][k][0][0][0] = ""+antal[i];
k++;
}
}
trace(fest_data)
}
If someone could guide me a bit.. I made this from and example and don't really know where to begin searching for errors..
thanks...
|