Path from one movie clip to another

This is entirely about variables, not controlling the clips.
I thoroughly understand the path from level 0 to any clip, but can’t seem to figure out a path from one clip to another. _root.myclip1.myclip2 and etc work great, but when I try to address myclip1 from myclip2 it won’t work. I have been required to use_global.variable to get variables to show up in one movie clip when it was generated in another clip. Here is an example. If I say that a=3 at level 0, it can easily be addressed in level1 with var a = _root.a but if it is generated in any movie clip, such as myclip2 then I can’t get at it in myclip1 without the _global variable. I want to set a = 3 in myclip2 and be able to see it in myclip1 with some sort of path. Can anyone help?

in order to address myclip1 from myclip2, you’d need to use _parent instead of _root. using _parent is called relative addressing. it facilitates how objects within objects can talk to their parent objects–that is, the objects they are sitting in.

since myclip2 resides in myclip1, myclip1 is its parent. (think of a box within a box.)

Thank you liam for the quick response.

I understand that when you have myclip2 inside of myclip1, then myclip 2 can address variables in myclip1(parent).

a=3 is set inside myclip1. myclip2 can access this variable with a=_parent.a and the myclip2 can now use the value of a.

Problem is how does myclip1 access a variable inside myclip2. Example:

Let’s say inside myclip2 we set a variable a=3. How can myclip1 which is the parent find out what the child is doing. We don’t have such a thing as a= _child.a do we?

I even have no problem when I have 3 clips, such as myclip1 thru three, and i want myclip3 to get a variable that was set in the root.

I can use inside myclip3 the following:
a=_root.a or a=_parent._parent.a
Also I can get variable a out of myclip 2 and into 3 with a simple a=_parent.a

But again I can’t figure out how to get myclip2 to find out what is going on in the chid.

If I am in myclip3 and set a=3 I can’t figure out how myclip2 or even the root can access that variable. I have tried all sorts of things to no avail. It seems like we need a child command, but I have not seen that used.
I hope I am not confusing this with my attempt at explanation.

Originally posted by tommytx
Let’s say inside myclip2 we set a variable a=3. How can myclip1 which is the parent find out what the child is doing. We don’t have such a thing as a= _child.a do we?

myclip2.a :wink:

Kax, thanks for you response but it didn’t work.

I made a clip in the library named myclip. Then drug it to the main screen.
Gave it an instance of myclip1, went to myclip1 and typed into action code a=3.
Went back to main level 0 and typed in the level 0 action area trace(myclip1) and got undefined.
I placed in myclip1 action area trace(a) and got 3.
Any other ideas, or did I misunderstand what you were saying.

kax, sorry about that…what I typed into level 0 action area was trace(myclip1.a) not jus trace(myclip1) as I stated.
Sorry that was just a typo.

the scripts are executed first in the parent MovieClip.
therefore, when the trace action is executed, technically the variable a doesn’t exist.

that’s why it returns undefined. :wink:

Thanks Kax, you have been a big help I think. Will let you know tomorrow.

I will try the test again in the morning, as it is 4:00 am here. I will leave the same setup, but will make a button that when pressed, jumps to frame 1. That will rerun the parent code after the child has been set. It sounds like you are rite on cue…Thanks a lot.

I will post my results tomorrow.

Ok Kax, I tried what you said unless I mis-understood what you were explaining. Here is what I did to no avail.

  1. I made a simple clip with nothing in it except in the action Ifor myclip1 I typed:
    line 1 a=3
    line 2 _root.gotoandPlay(1).
    line 3 gotoAndPlay(1).

  2. I drug a copy of myclip to the stage and gave it an instance of myclip1. I made sure the same code was in myclip1 on the stage.

  3. In the root, I typed trace(a) and I still get undefined.

  4. Can you tell me what I am missing?

  5. I understand as you said, the first time I scanned the root, the variable a has not been set at the time of the trace. But wouldn’t the gotoAndPlay(1) that I placed in myclip1 have made the trace in the root run again to show the new value which has now been set in myclip1? Therefore I expected
    1st entry = undefined
    2nd entrh = 3
    But I got undefined both times.

  6. Still get undefined.