How to pass variables values from movie clips to the main stage

Hi all,

Newbie here. I have been studying up a storm but the learning curve is steep.

I’m perplexed by passing variables from a movie clip to the main stage.

I have a movie clip with an instance name mc1 on the main stage. In that movie clip I declared a variable

c = 5;

on the first frame inside the mc1 movie clip.

I thought I could access that variable inside mc1 from the main stage by placing this on the first frame of the main stage:

x = _root.mc1.c;

Obviously I don’t understand what is going on in terms of scope of variables because I keep getting an undefined statement in my variable x.

Some insight would be appreciated.


Thanks,
Greg

Well, you’re targetting the variable correctly. Just make sure that the variable c has been defined before you assign its value to the variable x. :slight_smile:

Thanks for the reply.

I did assign a value to c in the movie clip.

“Oddly” if I made my movie two frames long on the main stage then x did get the value from the movie clip. But if I didn’t make the movie on the main stage two frames long x remained undefined.

Sadly, I don’t get it. Obviously I’m not grasping something about the main time line inregards to the movie clip. I knoe the movie clip runs continuously.

Thanks,
Greg

The code in the main timeline is executed before the code in the movie clip! That’s why you get [font=courier new]undefined[/font] when you try to get its value whithin the same frame. :stuck_out_tongue:

… I suppose I should have said it in my previous reply.