PDA

View Full Version : Dynamic Movie Clip naming



m0nk3y
December 11th, 2007, 10:35 AM
Hi

I'm having a little trouble adding dynamic names in ActionScript 3.0 like I could in AS2.0, can anyone help please?



var i:Number=1;
var mc[i]:MovieClip();

jamiller
December 11th, 2007, 10:41 AM
have you tried .name?


mc.name = "newName";

m0nk3y
December 11th, 2007, 12:29 PM
How do I now access the movie clip by that name?

Here's my code, the addChild line isn't working?:



var mc:MovieClip;
mc = new Left();
mc.name = "left"+i;
this.addChild("left"+i);

soulwire
December 11th, 2007, 02:20 PM
use addChild(mc)

m0nk3y
December 11th, 2007, 03:01 PM
Yeah, I've worked that bit out, thank you Soulwire.

I need to access using a for loop later on each of the names, but can't quite figure that out, keep getting "Cannot access a property or method of a null object reference."

It seems so much harder than in AS2.0, I'm sure it's because I'm not used to it enough yet.

Felixz
December 11th, 2007, 05:26 PM
getChildByName()

m0nk3y
December 12th, 2007, 03:41 AM
Thanks Felixz. I had been having a little difficulty in getting that to work, but I've managed to figure out what was wrong.

Appreciate everyone's help on this, thanks.