A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Parent/child variable

  1. #1
    Navigation Nazi
    Join Date
    Nov 2000
    Posts
    131

    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.

  2. #2
    Senior Member Steven FN's Avatar
    Join Date
    Mar 2010
    Location
    CA, USA
    Posts
    276
    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)."

  3. #3
    Navigation Nazi
    Join Date
    Nov 2000
    Posts
    131
    Yes, that worked, thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center