frez
March 20, 2006, 1:00pm
1
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.
myMovieClip
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?
e.g.
function changeSize ([COLOR=DarkRed]num[/COLOR]) {
[COLOR=SeaGreen]myMovieclip.rectangle[/COLOR]+[COLOR=DarkRed]num[/COLOR].[COLOR=RoyalBlue]xscale[/COLOR] = 2;
}
thanks
frez
March 20, 2006, 4:54pm
2
after an exhaustive search of the docs …
solved the problem by using the global setProperty function …
would still like to know how to the above though (if possible).
frez:
after an exhaustive search of the docs …
solved the problem by using the global setProperty function …
would still like to know how to the above though (if possible).
function changeSize(num) {
myMovieclip["rectangle"+num]._xscale = 2;
}
daleth
March 20, 2006, 7:06pm
4
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…
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