-
Parent/child variable
I'm trying to control a movieclip from the parent. I need to run the same movieclip differently depending on what's happening in the parent.
On the parent timeline, I declare the variable and set it.
var Loop;
var LoopCounter;
LoopCounter = 1;
I want the movieclip timeline to loop in some cases and not others, hence the variable here.
if (Loop==false) {
play();
movGametic.play();
}
In the movieclip, I have an action on a frame that replays a set of frames unless the Loop variable is set to false. So once it's looped 5 times it will continue playing. (at other points, this doesn't happen, hence the variable).
LoopCounter = LoopCounter + 1;
if (LoopCounter > 5) {
Loop = false;
}
I'm sure there's a way to do this other than the way I've set it up, but I'd also like to understand how to pass these variables.
-
Hi, i would start with type casting your variables:
Code:
var Loop:Boolean = false;
var LoopCounter:int = 1;
To get the variables from the parent, use "MovieClip(parent)."
For the counter increment, you can use the shorthand:
Code:
MovieClip(parent).LoopCounter++;
Just make sure to use "MovieClip(parent)" when referring to its variables. For some reason just "parent" doesn't work inside nested MovieClips. Something to do with not being able to set variables to the DisplayObjectContainer sealed class.
Hope that works out. Also, for root use "MovieClip(root)."
-
Yes, that worked, thanks!