Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2006-04-09
Medium Priority
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

Aneesh Chopra earned 1400 total points
ID: 16414745

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

by:Dushan De Silva
ID: 16459637
From the initial point, put all of the paths to global varibles.

BR Dushan

Assisted Solution

jack_p50 earned 600 total points
ID: 16585385
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(....);

Author Comment

ID: 16593742
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
ID: 16593836
Yes, you got it right

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
Suggested Courses

810 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