[haXe] converting code
Michael Pliskin
pl at tepkom.ru
Mon Apr 16 10:39:33 CEST 2007
Hello Orlando,
OL> mv = _root;
OL> depth = 0;
OL> tileW = 20;
OL> tileH = 20;
OL> for(var b=0; b<=10; b++){
OL> for(var a=0; a<=10; a++){
OL> var name = "t" + depth;
OL> mv.attachMovie(Tiles, name, ++depth);
OL> mv[name]._x = a*tileW;
OL> mv[name]._y = b-*tileH;
OL> }
OL> }
You code can be re-written like this:
for (b in 0...11) {
for (a in 0...11) {
var name = "t" + depth;
// are you sure you can use the same ID for all of your MCs?
var namedMovie = mv.attachMovie(Tiles, name, ++depth);
namedMovie._x = a * tileW;
namedMovie._y = b * tileH;
/*
another way: Reflect.field(mv, name)._x = a * tileH;
*/
}
}
OL> My doubt is about the use of [] to call some function/proprerty, (this I
OL> know about Reflect class help this), but and the creation the new instance,
OL> (movie clip), having a name String: var name = "t" + depth;mv.attachMovie();
As the example above shows, you can use Reflect.field(object, name) to
get the field. To create instances, look into this thread for
discussion:
http://lists.motion-twin.com/pipermail/haxe/2007-April/008423.html
OL> Other thing that I know is the for should be used while. This code is based
OL> in tonipa. Then, if somebody have answer for me. Thanks
You can still use for, just in a slightly different way, see the
example above. Of course, while will also work.
--
Best regards,
Michael mailto:pl at tepkom.ru
More information about the Haxe
mailing list