Hi Flash coders!

I'm doing a maze game and I have a problem with moving a movie clip with the
arrow keys

My AS2 code:
map = new Array();
generateMap();
drawIt(map);
_root.attachMovie("item", "sprite", 10000);
sprite._y = 10;
sprite._x = 10;
sprite.px = 2;
sprite.py = 1;
sprite.onEnterFrame = function() {
   if (key.isDown(key.LEFT) && (map[this.py][this.px-1] != 1)) {
       this.px--;
       this._x -= 20;
   }
   if (key.isDown(key.RIGHT) && (map[this.py][this.px+1] != 1)) {
       this.px++;
       this._x += 20;
   }
   if (key.isDown(key.UP) && (map[this.py-1][this.px] != 1)) {
       this.px--;
       this._y -= 20;
   }
   if (key.isDown(key.DOWN) && (map[this.py+1][this.px] != 1)) {
       this.px++;
       this._y += 20;
   }
};
//_________________________________________________
function drawIt(theMap) {
   var pos = 0;
   for (var y = 0; y<20; y++) {
       for (var x = 0; x<20; x++) {
           pos = x+(y*20);
           if (theMap[y][x] == 1) {
               _root.attachMovie("myTile", "tile_"+pos, pos);
               _root["tile_"+pos]._x = x*10.5;
               _root["tile_"+pos]._y = y*10.5;
           }
       }
   }
}
//------------------------------------------------
function generateMap() {
   map[0] = new Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1);
   map[1] = new Array(1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1,
0, 1);
   map[2] = new Array(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0,
0, 1);
   map[3] = new Array(1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1,
0, 1);
   map[4] = new Array(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0,
0, 1);
   map[5] = new Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1);
   map[6] = new Array(1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 1);
   map[7] = new Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1);
   map[8] = new Array(1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
1, 1);
   map[9] = new Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1);
   map[10] = new Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
1, 0, 1);
   map[11] = new Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1);
   map[12] = new Array(1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1);
   map[13] = new Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1);
   map[14] = new Array(1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1,
1, 0, 1);
   map[15] = new Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1);
   map[16] = new Array(1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
1, 1, 1);
   map[17] = new Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1);
   map[18] = new Array(1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 1);
   map[19] = new Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1);
   map[20] = new Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1);
   map[21] = new Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1);
}

------------------------------
What is wrong? I think it should work.
But actually the arrow key doesn't work in any file. Is that a Flash program
problem or I'm wrong with the script?
If anyone could help me...
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to