this works great for me (a part of a larger code I wrote, ignore what you
need) Ball draws the... emm.... ball :) :
for (var i:int = 0; i < 10; i++) {
for (var j:int = 0; j < 10; j++) {
var lineRndomColor:Number = Math.round((Math.random()*
0xFFFFFF));
var fillRndomColor:Number = Math.round((Math.random()*
0xFFFFFF));
var my_ball:Ball = new Ball(lineRndomColor, fillRndomColor, 15);
addChild(my_ball);
my_ball.x = (i * 30) + my_ball.width;
my_ball.y = (j * 30) + my_ball.width;
}
}
hope it works for you.
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Flashcoders
mailing list
Sent: Friday, November 25, 2005 11:11
To: [email protected]
Subject: Re: [Flashcoders] Dynamic variables in as3
Importance: Low
> for(var i:Number =0;i < acRate; i++){
> var ['p'+i]:MovieClip = new MovieClip()
> this['p'+i].x = i*10
> this['p'+i].y = i*10
> }
>
> Which doesn't work of course. Does anybody have a work around for this,
> or is it no longer possible to create undeclared variables at run time.
>
The only reason I can think of that that wouldn't work is that you can't
declare dynamic variables. So you could do it like this:
for(var i:Number =0;i < acRate; i++){
this['p'+i] = new MovieClip();
this['p'+i].x = i*10;
this['p'+i].y = i*10;
}
But that's not really good OOP. What you should do instead is build an
array of references to your movie clips, like this:
var clips:Array = new Array();
for(var i:Number =0;i < acRate; i++){
clips[i] = new MovieClip();
clips[i].x = i*10;
clips[i].y = i*10;
}
ryanm
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders