vendredi 26 février 2016

Movieclip problems in AS3 tile based

I'm making the TonyPa ISO tutorials in AS3. I've traduced the code to AS3 and works well but I have a question because I can't solve the problem.

When I create the tiles, I create an empty MC to hold it, making this:

var tiles: MovieClip = new MovieClip();
var back: MovieClip = new MovieClip(); = "tiles";

Then, I attach the tiles doing that:

game.clip = tiles;
var namer: String = "t_" + y + "_" + x;
game[namer] = new game["Tile" + map[y][x]]();
var myTile: _myTile = new _myTile();
game.clip.addChild(myTile); = namer;
myTile.x = (x * game.tileW);
myTile.y = (y * game.tileH);

But the trace says "undefined". I know, the correct code for show the name is changing the tracer to


But in another function, I have to change the tiles, and when I try to get the name of the tile, it says is "undefined", because I ned to get the name using this:

game[namenew] = new game["Tile"+map[ynew][xnew]]();
game.clip[nameold].namer = namenew;
game.clip[namenew].x = (xnew*game.tileW);
game.clip[namenew].y = (ynew*game.tileH);

The variables namenew, ynew, xnew, nameold, etc. are defined in the entire function, It doesn't matter. What I want to know is, how I can attach the Movieclip _myTile to game.clip? The old AS2 code is this:

var name = "t_"+i+"_"+j;
game[name] = new game["Tile"+map[i][j]]();
game.clip.attachMovie("tile", name, i*100+j*2);
trace (trace(game.clip[name]); // Shows the name 4example: level10.tiles.t_3_5


Aucun commentaire:

Enregistrer un commentaire