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

Posted on 2006-04-09
Last Modified: 2010-04-03
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.

Question by:dmehran
    LVL 34

    Accepted Solution


    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.

    LVL 17

    Expert Comment

    From the initial point, put all of the paths to global varibles.

    BR Dushan
    LVL 4

    Assisted Solution

    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
    class movies {
      static var mc1:MovieClip, mc2:MovieClip;

    in your code:
    movies.mc1 = attachMovie(...);
    movies.mc2 = movies.mc1.attachMovie(....);

    Author Comment

    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?
    LVL 34

    Expert Comment

    by:Aneesh Chopra
    Yes, you got it right

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
    I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
    The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
    The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now