all groups > flash actionscript > february 2005 >
You're in the

flash actionscript

group:

Dynamically naming "createEmptyMovieClip"



Re: Dynamically naming "createEmptyMovieClip" David Stiller
2/8/2005 3:42:53 PM
flash actionscript: Stasa,

[quoted text, click to view]

The reason your code doesn't work is because you're not referencing any
MovieClip instances. You're only referencing a String.

for (i=0; i< 2; i++) {
_root.createEmptyMovieClip('a'+i, i);
with (a+i) {
beginFill (0x00ff00, 60);
moveTo(100, 100);
lineTo(100, 300);
lineTo(300, 300);
lineTo(300, 100);
lineTo(100, 100);
endFill();
}
}

That with() loop needs to actually refer to a movie clip. If you trace
out the value of a+i, it would be "a0", "a1", etc. ... and those are
strings. If you use brackets, you can get what you need: brackets will
allow you to use strings and variables for paths.

with (_root["a" + i]) { ... }


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

Dynamically naming "createEmptyMovieClip" Stasa
2/8/2005 8:28:12 PM
I need to create dynamically few movie clips with names a0, a1, a2... and then
to place them on different x coordinates... the code look something like this,
but won't work. Thank's for anny help. for(i=0; i< 2; i++){
_root.createEmptyMovieClip('a'+i, i); with (a+i) {
beginFill(0x00ff00, 60); moveTo(100, 100);
lineTo(100, 300); lineTo(300, 300); lineTo(300, 100); lineTo(100,
100); endFill(); }} a0._x = 300; a1._x = 400;
Re: Dynamically naming "createEmptyMovieClip" TimSymons
2/8/2005 8:48:24 PM
The createEmptyMovieClip returns a reference to the new movieClip instance. Try
replacing: _root.createEmptyMovieClip('a'+i, i); with(a+i) { With the
following: temp_mc = _root.createEmptyMovieClip('a'+i, i); with(temp_mc) { I
would also try to use the with() command to set the _x parameter. It will make
sure that you are referencing the correct instance. HTH. Tim
AddThis Social Bookmark Button