Procedural object naming

i’m sure this is a simple one … but i can’t seem to figure out the syntax in action script for procedurally building an object name.

i have a function that creates a movie clip and then procedurally creates 10 rectangles inside that clip.


  • rectangle1
  • rectangle2
  • rectangle3
  • rectangle4

i have another function that lets me modify properties of a particlar rectangle given it’s id number.

what is the syntax for accessing that rectangle object?


function changeSize ([COLOR=DarkRed]num[/COLOR]) {

    [COLOR=SeaGreen]myMovieclip.rectangle[/COLOR]+[COLOR=DarkRed]num[/COLOR].[COLOR=RoyalBlue]xscale[/COLOR] = 2;



after an exhaustive search of the docs …

solved the problem by using the global setProperty function … :slight_smile:

would still like to know how to the above though (if possible).

function changeSize(num) {
	myMovieclip["rectangle"+num]._xscale = 2;

you could also use eval:

function changeSize (num) {
clip = eval(“myMovieclip.rectangle”+num);
clip._xscale = 2;

Stringy, does that notation imply an array, or is that a way I didn’t know of of accessing child clips?

It is array notation but it’s just accessing a variable instance name. It was made to confuse noobies…:smiley:

awesome. :party:

this is a great forum.

thanks guys.

Yes, any object and its properties can be referenced in terms of an associative array. In fact, objects which are actually instances of the Array class are just regular objects (associative arrays) which use numbers instead of words for it properties :slight_smile: