how to define an instance of a movie clip globaly as oppose to a relative target path

Hi, I am working on a rather large flash project and I don't want to define target paths for my nested movie clip instances. It is basically very messy trying to refer to my movie clips using paths like _root.MC1 or _parent._parent.MC2 ... ,If in the future I have to move my movie clips around, it will be difficult a task to update the corresponding traget paths. Is there a way to define global paths for my movie clips so I can refer to them from anywhere in my flash project and not worry about updating my  target paths later? For simplicity you can assume that all my movie clips are created in the same .fla file (no external movie clips). Also I am using Flash 8 and action script 2.0.

thanks
dmehranAsked:
Who is Participating?
 
Aneesh ChopraCommented:
Hi,

In AS 2.0 classes, you can define static variables and store the path of your movieclip in it.

for example:
class name is myClass:

Static var mcReference:MovieClip;
-------------
myClass.mcReference = _root.mc1;
--------------

now this variable will be available to all  classes or movieClip as it..
you can access it anywhere as shown below..
-----------
myClass.mcReference._width; // this will return the width of _root.mc1 movieClip.
----------

Rgds
Aneesh
0
 
Dushan De SilvaTechnology ArchitectCommented:
From the initial point, put all of the paths to global varibles.

BR Dushan
0
 
jack_p50Commented:
Yeah, when calling attachMovie, assign the movieclip it returns to some global or static class variable.

Example 1:

..
_global.mc1 = attachMovie(....);
_global.mc2 = _global.mc1.attachMovie(....);

Example 2:

create a new class, save it to movies.as
class movies {
  static var mc1:MovieClip, mc2:MovieClip;
  ....
}

in your code:
movies.mc1 = attachMovie(...);
movies.mc2 = movies.mc1.attachMovie(....);
0
 
dmehranAuthor Commented:
Thanks for the answers, I posted this question a while ago and forgot to come back to it. Aneesh, with your static variable in a class method then, if I ever move my movie clips around in the future, I would only need to change the path assigned to the static variable accordingly, right?
0
 
Aneesh ChopraCommented:
Yes, you got it right
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.