Re: [Flashcoders] bidimensional array in as
maybe a silly question, but here i go anyway: how would you write something like this in actionscript: int matrix[3][3]; for(i=0;i<3;i++) for(j=0;j<3;j++) matrix[i][j]=0; i've done something like this in my code, mtasc doesnt complained, but the program doesnt work, and i have a feeling that something wrong. This has been answered twice, but without explaining *why* it works this way. The fact is, there are no multidimensional arrays in AS (ECMA). What you have instead is an array of arrays. As such, the child arrays must be declared before they can have elements assigned to them. ryanm ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] bidimensional array in as
On Oct 31, 2005, at 9:24 AM, Gregory wrote: You must create empty arrays first, like this: // bidimensional array in AS var matrix2:Array = []; for(i=0;i<3;i++){ matrix2[i] = []; for(j=0;j<3;j++){ matrix2[i][j]=0; } } trace(matrix2); Yea, I'm a dufus. I think I was in AS3 mode when i posted that - then again, I didn't test it either... i'll be quiet now. :) Jon ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] bidimensional array in as
You must create empty arrays first, like this: // bidimensional array in AS var matrix2:Array = []; for(i=0;i<3;i++){ matrix2[i] = []; for(j=0;j<3;j++){ matrix2[i][j]=0; } } trace(matrix2); -- original message -- >On Oct 31, 2005, at 7:22 AM, cornel wrote: >> hi >> maybe a silly question, but here i go anyway: >> how would you write something like this in actionscript: >> >> int matrix[3][3]; >> for(i=0;i<3;i++) >> for(j=0;j<3;j++) >> matrix[i][j]=0; >> >> i've done something like this in my code, mtasc doesnt complained, but >> the program doesnt work, and i have a feeling that something wrong. >> >> i would appreciate any help >> cornel >Unlike C, Actionscript can't create a two-dimensional array like that. >var matrix = []; >for (;i<3;i++) matrix[i] = [0]; >That's the super shorthand way of doing it. >cheers, >Jon -- Best regards, Gregory http://GOusable.com Flash components development. Usability services. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] bidimensional array in as
int matrix[3][3]; for(i=0;i<3;i++) for(j=0;j<3;j++) matrix[i][j]=0; You have to create the initial array and then create any sub array. Kinda like: matrix = []; for(i=0;i<3;i++) { matrix[i] = []; for(j=0;j<3;j++) { matrix[i][j] = 0; } } ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] bidimensional array in as
On Oct 31, 2005, at 7:22 AM, cornel wrote: hi maybe a silly question, but here i go anyway: how would you write something like this in actionscript: int matrix[3][3]; for(i=0;i<3;i++) for(j=0;j<3;j++) matrix[i][j]=0; i've done something like this in my code, mtasc doesnt complained, but the program doesnt work, and i have a feeling that something wrong. i would appreciate any help cornel Unlike C, Actionscript can't create a two-dimensional array like that. var matrix = []; for (;i<3;i++) matrix[i] = [0]; That's the super shorthand way of doing it. cheers, Jon ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] bidimensional array in as
hi maybe a silly question, but here i go anyway: how would you write something like this in actionscript: int matrix[3][3]; for(i=0;i<3;i++) for(j=0;j<3;j++) matrix[i][j]=0; i've done something like this in my code, mtasc doesnt complained, but the program doesnt work, and i have a feeling that something wrong. i would appreciate any help cornel ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders