Copy link to clipboard
Copied
Hey guys, really simple question--how do I get the frame number of a movieclip within a movieclip? Say I have mc2 nested within mc1. Whenever i try to say mc1.mc2.currentFrame, I get
TypeError: Error #1010: A term is undefined and has no properties.
at blobgame2_fla::MainTimeline/loop()
I would attach my fla if this forum would let me.
Copy link to clipboard
Copied
It depends on how you added mc2 to mc1. If you did it manually, then what you show would be correct as long as you assigned those instance names to the movieclips via the Properties panel.
If you added mc2 to mc1 dynamically, then you either need to target it directly (mc2.currentFrame) or via using 'getChild...'-type targeting... such as in mc1.getChildAt(0).currentFrame (might need to cast it as a MovieClip)
Copy link to clipboard
Copied
You shouldn't be doing this. For one thing, you're likely to wind up with race conditions that mean you can never be sure what exists yet and what doesn't. For another, if you need to change the way mc1 is built, then everything with a "hard" reference to mc2 will break until you dig around and fix it. You should build mc1 to do whatever needs to be done or generate an event (depending on your real end goal).
What are you trying to do that you need the frame number for?
Copy link to clipboard
Copied
Either mc1 or mc2 is undefined. Trace them to see... and Ned's answer is spot on as well.