Hey Ben. I've been kinda MIA lately but I think I can solve this one for you
A little background. When you load an external movie it replaces the "target" clip that you assign in the loader. So if I had a main stage with a child clips called "mc1" and a movie called "mc2" inside of the "mc1", I could do something like this (assuming this code is on your root timeline)
var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.loadClip("blue.swf", this.mc1.mc2);
- var mcLoader:MovieClipLoader = new MovieClipLoader();
- mcLoader.loadClip("blue.swf", this.mc1.mc2);
Now I can access all the objects of my loaded clip simply by using this target:
trace(this.mc1.mc2._alpha); // example of a property or
trace(this.mc1.mc2.myVariableName); // variable located in the loaded clip
- trace(this.mc1.mc2._alpha); // example of a property or
- trace(this.mc1.mc2.myVariableName); // variable located in the loaded clip
So you can get the variable content with its path from where ever your code is located or when you define the variable you could specify that its global. For example.
and then access it with
This solution is generally considered bad practice because you get a bunch of variables that exist everywhere and pollute the global scope. Best bet is to go with the first version.
Theres likely a second issue here though, and thats that you may be calling the variable before the external clip has actually loaded and written the variable. Actionscript processes code very quickly and so two lines of code may fire only a fraction of a second behind each other. This is usually much too quick for the http request thats actually retrieving and loading the external file. The result is that Flash says "I checked for the variable you want but it doesn't exist at this moment in time so I won't look again and I'll say its undefined"
The way around this is to wait to call the variable until you know the the clip has loaded and the variable exists. This is where callbacks come in. You basically need to tell flash to do something when another process completes (loading a file, playing a video, etc)
var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.addListener(this);
mcLoader.loadClip("blue.swf", this.mc1.mc2);
// this is the callback function and it runs when the first frame of AS in the external file is loaded
function onLoadInit(mc:MovieClip) {
// flash knows that mc = the path to your target clip
trace(mc.x); // show the value of x after the clip is loaded
}
- var mcLoader:MovieClipLoader = new MovieClipLoader();
- mcLoader.addListener(this);
- mcLoader.loadClip("blue.swf", this.mc1.mc2);
- // this is the callback function and it runs when the first frame of AS in the external file is loaded
- function onLoadInit(mc:MovieClip) {
- // flash knows that mc = the path to your target clip
- trace(mc.x); // show the value of x after the clip is loaded
- }
Make sense?
If at first you don't succeed F1... If that doesn't work try Google!
//// Designer, Developer & Teacher - Interactive, Motion and 3D \\\\
Portfolio at WhenImNotSleeping.com