Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 12-05-2001, 11:23 AM   #1
jess
Registered User
 
Join Date: Dec 2001
Location: UK
Posts: 27
Default Multi Dimensional Arrays

HELP ME SOMEONE PLEEEEASE!!! I need to create a multi-dimensional array...(?) - and thats all I know.... (well almost!)
jess is offline   Reply With Quote
Old 12-05-2001, 11:39 AM   #2
IFZen
Even graphists R objects
 
IFZen's Avatar
 
Join Date: Jun 2001
Location: Paris
Posts: 273
Default

The thing is to build arrays of arrays.
For instance, you can define a two dimensional array like this :

var tMultiArray = new Array();
tMultiArray.push(new Array());

tMultiArray[0].push("toto");
tMultiArray[0].push("titi");

trace(tMultiArray[0][0]);
trace(tMultiArray[0][1]);

will give you that output :
toto
titi

Hope it helps,
BZen
__________________
Oh Lord, shut me down !
IFZen is offline   Reply With Quote
Old 06-17-2003, 02:33 PM   #3
avatar
Senior Member
 
avatar's Avatar
 
Join Date: May 2002
Location: Belgium - Antwerp
Posts: 456
Default

I was looking for a solution on the forums and this thread was close to my problem so maybe someone could help me...

How do you "push" two arrays?
ActionScript Code:
tMultiArray = new Array(); two = new Array(); two = [20, 30] tMultiArray[0].push(two); trace(tMultiArray[0][0]);
this doesn't work, unfortunately... what's wrong?
__________________
Cheers,
Avatar
http://www.12create.be
avatar is offline   Reply With Quote
Old 06-17-2003, 02:43 PM   #4
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,875
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

your problem is tMultiArray[0] isnt an array when you try to push something on it. you have to make it one first...

ActionScript Code:
tMultiArray = new Array(); two = new Array(); two = [20, 30] tMultiArray[0] = new Array(); tMultiArray[0].push(two); trace(tMultiArray[0][0]); // 20, 30
__________________
(6)
senocular is offline   Reply With Quote
Old 06-17-2003, 02:48 PM   #5
mgb
New Member
 
Join Date: Jan 2001
Posts: 245
Default

The most straightforward way is to make each array element an array-

tMultiArray = new Array();

tMultiArray[0] = new Array();
tMultiArray[1] = new Array();
.
.
.
tMultiArray[n] = new Array();

tMultiArray[0][0] = "a";
tMultiArray[0][1] = "b";

etc.

trace(tMultiArray[0][0]+" . "+tMultiArray[0][1]);

~mgb
mgb is offline   Reply With Quote
Old 06-17-2003, 03:03 PM   #6
avatar
Senior Member
 
avatar's Avatar
 
Join Date: May 2002
Location: Belgium - Antwerp
Posts: 456
Default

thanx guys, got it working now...
__________________
Cheers,
Avatar
http://www.12create.be
avatar is offline   Reply With Quote
Old 06-18-2003, 04:36 AM   #7
red penguin
[^\d\D]
 
red penguin's Avatar
 
Join Date: Jun 2001
Location: Brooklyn, NY
Posts: 3,254
Default

Like dees, mayn!
ActionScript Code:
Array.prototype.arr_two_dee=function(x,y) {     for (var i=0;i<x;i++) {         this[i]=[y];     } }; // use arr_test=[]; arr_test.arr_two_dee(4,4); // a grid for (x=0;x<=3;x++){     for (y=0; y<=3; y++){         arr_test[x][y]='['+x+']['+y+']';     } }
__________________

komielan.com
red penguin is offline   Reply With Quote
Old 07-02-2008, 03:37 AM   #8
PeterTang
Peter Tang
 
Join Date: Dec 2007
Location: Singapore
Posts: 8
Default

I having the headache on the multi-dimensional array for the past few days. Finally I got it solved after reading through the thread overhere. Thanks.

But I still have the question for the Push in the script here. What do this push do in the array? I could not understand? Can anyone tell me more about it?

Thanks in advanced.
PeterTang is offline   Reply With Quote
Old 03-26-2012, 01:09 AM   #9
palabattle
Registered User
 
Join Date: Feb 2012
Posts: 3
Default

Quote:
Originally Posted by jess View Post
HELP ME SOMEONE PLEEEEASE!!! I need to create a multi-dimensional array...(?) - and thats all I know.... (well almost!)
Let's me introduce to you a good way with an example.

XML content:

Code:
<?xml version="1.0" standalone="yes"?>
<RECORDS>
  <RECORD>
    <ID>1</ID>
    <AlbumId>1</AlbumId>
    <SongId>1</SongId>
    <CommentWriter>asdasd</CommentWriter>
    <CommentReader>asdasdsddddd</CommentReader>
  <RECORD>
<RECORDS>

Actionscript 2.0

Code:
function processXMLData(success)
{
  if (success)
  {
	comments = this.firstChild.childNodes;
	for (var i = 0; i < comments.length; i++){
		albumId = comments[i].childNodes[1].childNodes; //AlbumId
		songId = comments[i].childNodes[2].childNodes; //SongId
		commentWriter = comments[i].childNodes[3].childNodes; //CommentWriter
		commentReader = comments[i].childNodes[4].childNodes; //CommentReader
		
        //Create the first array
		var tMultiArray = new Array();
        //Create the child array of fist array
		var tMultiArrayChild = new Array();		
		
        //Initial value for the child array
		tMultiArrayChild = ["AlbumId", albumId];
                //Then push the child to fist array
		tMultiArray.push(tMultiArrayChild);

        //Do it again
		tMultiArrayChild = ["SongId", songId];
		tMultiArray.push(tMultiArrayChild);
		
        //Do it again
		tMultiArrayChild = ["CommentWriter", commentWriter];
		tMultiArray.push(tMultiArrayChild);
		
        //Do it again
		tMultiArrayChild = ["CommentReader", commentReader];
		tMultiArray.push(tMultiArrayChild);
		
        //We need to collect all multiarray so then we can reuse it
		commentInfo.push(tMultiArray);		
	}

    //When all things are done, then just try to get all multiarray from commentInfo
	for (var i = 0; i < commentInfo.length; i++){
		trace(commentInfo[i][0][0] + "|" + commentInfo[i][0][1]);
		trace(commentInfo[i][1][0] + "|" + commentInfo[i][1][1]);
        trace(commentInfo[i][2][0] + "|" + commentInfo[i][2][1]);
        trace(commentInfo[i][3][0] + "|" + commentInfo[i][3][1]);
	}
  }
  else
  {
    content="Today's news is not found";
  }
}

What is the result of code above? Take a look at this.

Code:
AlbumId|1
SongId|1
CommentWriter|asdasd
CommentReader|asdasdsddddd
AlbumId|1
SongId|2
CommentWriter|qwerqwrqwrqwr
CommentReader|erqwrqrqwrqwr
AlbumId|1
SongId|3
CommentWriter|werwerwer
CommentReader|werwerwer
AlbumId|1
SongId|3
CommentWriter|awerqrqwr
CommentReader|rqwrqwrqwr
AlbumId|2
SongId|1
CommentWriter|eqwrqwrqwr
CommentReader|qwrqwrqwrqwr
AlbumId|1
SongId|1
CommentWriter|asdasdasd12
CommentReader|asdasdasd1
AlbumId|1
SongId|1
CommentWriter|241234123
CommentReader|123123213
AlbumId|1
SongId|1
CommentWriter|241234123a
CommentReader|123123213
AlbumId|1
SongId|1
CommentWriter|asdasd
CommentReader|asddddd
I hope this can help.
palabattle is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
two dimensional arrays with shared objects! blucinzano ActionScript 2.0 2 11-29-2007 05:01 PM
multi level arrays panix ActionScript 1.0 (and below) 1 03-22-2004 03:20 AM
Initialising 2 dimensional arrays ferdymania ActionScript 2.0 4 10-31-2003 08:24 PM
Multi dimensional array Bob Sheehy ActionScript 1.0 (and below) 1 03-01-2002 08:11 PM
2 Dimensional Arrays Manifestation ActionScript 1.0 (and below) 10 01-27-2001 12:08 AM


All times are GMT. The time now is 08:18 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.