PDA

View Full Version : using getchildat() as movieclip



artheus
November 9th, 2009, 11:54 AM
Hey!

I've got a question that might make me look like a fool. But the question is:

Is it possible to somehow change a dynamic variable or call a dynamic function of an object using


container.getChildAt(index).variable = 234;
container.getChildAt(index).function();I mean, if I write a class with some functions and variables that are public. And I need many instances of that class (which extends MovieClip, and is tied to a object in the library) inside the container object. and I want to run some functions and set some variables of the first object in the container object when the container.numChildren > 10.

like this:



if (content.numChildren > 10) {
content.getChildAt(0).function1();
content.getChildAt(0).function2();

content.getChildAt(0).variable1 = "yay!";
}
I get the error



1119: Access of possibly undefined property variable1 through a reference with static type flash.display:DisplayObject.
and equivalent.


Cheers,
Artheus

artheus
November 9th, 2009, 12:00 PM
Hah! Found the answer myself.. Not as hard as I thought!



MovieClip(content.getChildAt(0)).variable1 = "yay!";


Cheers,
Artheus