-1

Can't seem to find any solution to my problem right now. I've seen some topics with 2d array undefined causing this error. here's the little code (fyi it's supposed to code an 2d array for my isometric engine)

public function collisionTest(coordinate:Point):Boolean {
var TableauCollision:Array = new Array();
            for (var spriteForX:int = 0; spriteForX < 29; spriteForX++)      {
                TableauCollision[spriteForX] = new Array();
                for (var spriteForY:int = 0; spriteForY < 29; spriteForY++) {
                TableauCollision[spriteForX][spriteForY] = 0;   
                }
            }
trace(TableauCollision[coordinate.x][coordinate.y]);
if (TableauCollision[coordinate.x][coordinate.y] == -1){
return (true);
}
return (false);
}

If i want a return for TableauCollision[coordinate.x] it's okay. But if i ask for TableauCollision[coordinate.x][coordinate.y] : error 1010, something isn't defined.

Thank you very very much for your help, since i know this topic has already been treated.

John, France.

Ivan Chernykh
  • 41,617
  • 13
  • 134
  • 146
  • Since i've tried many syntax from forums for creating this array, i think the problem may come from the coordinate object (it's a point). Maybe should I load the array apart from the if test. – John Biscuit Jan 27 '14 at 17:46
  • I separate the two parts of the function, didn't work. SOS ! – John Biscuit Jan 27 '14 at 17:53
  • The most bizarre thing is that, in fact, i'm able to do the test with coordinate.x and coordinate.y (if (coordinate.x = 12 & coordinate.y = 12) ...). I'm lost. – John Biscuit Jan 27 '14 at 17:59

2 Answers2

0

change this:

for (var spriteForY:int = 0; spriteForY < 29; spriteForY++) {
  TableauCollision[spriteForX][spriteForY] = 0;   
}

to this:

for (var spriteForY:int = 0; spriteForY < 29; spriteForY++) {
  TableauCollision[spriteForX].push(0);   
}
mika
  • 1,411
  • 1
  • 12
  • 23
0

Okay guys I solved the problem. Couldn't tell what it was. Changed the architecture of my program, works better. And is cleaner. Thank you.