Topic: Multi-Dimensional Arrays in AS (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=22525" title="Pages that link to Topic: Multi-Dimensional Arrays in AS (Page 1 of 1)" rel="nofollow" >Topic: Multi-Dimensional Arrays in AS <span class="small">(Page 1 of 1)</span>\

 
Relain
Paranoid (IV) Inmate

From: westernesse
Insane since: Jul 2000

posted posted 07-12-2004 13:34

hi all,
Motivated by the 20 liner compeition in the DHTML/JS forum i've set about trying to create my own landscape/heighfield rotater thing. I come from a C programming background and i thought it'd be pretty easy to just attach a load of movie clips to the stage and put them all (well references to them) into a 2d array so i could call back to them with ease for the moving and the jiggery pokery.

This is what i think sets up a 2d array called point_set, pretty strange syntax a mon avis...

code:
point_set = new Array;
point_set = [[],[]];



then as i attach the clips i do this:

code:
vertex = attachMovie("mcPoint", "n"+total, total);
point_set[[i],[j]] = vertex;



where total is just a simple counter var.

So far so good, but when i try and use the old nested for loops to actually reference parts of point_set, like this:

code:
onEnterFrame = function()
{

for (j=0; j<height; j++)
{
for (i=0; i<width; i++)
{
node = point_set[[i],[j]];
// rest of the function...



i only manage to get teh end five. The concept of the end is a bit weird due to the screen co-ords being annoyingly offset instead of nice carteisan.

The .fla is here, its not very elegant so far but you never know. The actual rotation is pretty amusing too, still i should be able to sort that out.

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 07-12-2004 22:22

I've never coded an ActionScript myself, but I'm I thought the syntax for multi-dimensionnal arrays in AS was the same as in JS, C, C++, ... that is :

code:
node = point_set[ [], [] ]
for (j=0; j<height; j++)
{
for (i=0; i<width; i++)
{
node = point_set[[i],[j]];
// rest of the function...
}
}

Are you sure, that the fact that you can access the last 5 items is not due to the fact that Flash allows the use of a "bastardized" syntax that actually only let you access the first item ( sub-array ) of the first dimension of your array ?

Just my 0.02?

Steve
Maniac (V) Inmate

From: Boston, MA, USA
Insane since: Apr 2000

posted posted 07-13-2004 04:19

I think your syntax is close but not quite there.
I think it should be node=point_set[i][j];

in other words, the "j" element of the "i" element of the array "point_set".

You might still use the [[...],[...]]; syntax to create the multidimensional array, but not to refer to a specific value in the set.

Poi's right to suppose that it's essentially the same as JavaScript, since they share a common ECMAScript lineage.

Take a glance at
http://www.macromedia.com/support/flash/ts/documents/twodarray.htm
and
http://actionscript-toolbox.com/arrayobject2.php

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 07-13-2004 08:31

Gosh! I should write code after a 4hours sleep and a full day of work. I obvsiouly thought node=point_set[ i ][ j ]; to access the elements of the array and sub arrays



(Edited by poi on 07-13-2004 10:13)

Relain
Paranoid (IV) Inmate

From: westernesse
Insane since: Jul 2000

posted posted 07-14-2004 11:31

yeah well i think i was writing it like that, i assumed that was how it worked just from c knowledge. but i think i was trying to create the array by like:

code:
Array1 = new ARRAY;
Array1 = [][];



and it didn't like that at all, i guess i moved to what seemed to be the correct syntax not thinking it would be a mix. Oh how complicated these 'new' languages are.

THanks for the help guys.

Relain
Paranoid (IV) Inmate

From: westernesse
Insane since: Jul 2000

posted posted 07-14-2004 11:48

yeah well i think i was writing it like that, i assumed that was how it worked just from c knowledge. but i think i was trying to create the array by like:

code:
Array1 = new ARRAY;
Array1 = [][];



and it didn't like that at all, i guess i moved to what seemed to be the correct syntax not thinking it would be a mix. Oh how complicated these 'new' languages are.

THanks for the help guys.



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu