PDA

View Full Version : Setting up variables for loaded movieclips.


gimmins
06-12-2005, 11:36 PM
Dear Flash developers,

I wonder if this type of question has already been posted, but since I cannot find satisfactory answer, I might as well post this question.

I have a movieclip loader in a loader.swf. I also have a rotate.swf file that has variables.

The problem is this. When I only run rotate.swf, the file works fine. However, when that rotate.swf is loaded from loader.swf, it doesn't give the result.

I am assuming that this is because for example if I declared and tried to access the variables in rotate.swf with something like the following code:

number = 0;
_level0.number = 50;

It will think that the number is located at the _level0 of loader.swf, not the _level0 of rotate.swf.

So my question is, is it possible to make the varibales work?

madgett
06-13-2005, 12:04 AM
The loaded movie is limited to it's own timeline. Variables are only accessible from that specific movie clip's timeline. However, what you can do is predefine variables in other movie clips on the root stage, then in the movie clip being loaded in reference the variable as _root.variable = 1 in that manner, and it will work.

Example, in s1.swf:
var s:Number;
var loader:MovieClip = _root.createEmptyMovieClip("loader", 1);
loader.loadMovie("s2.swf");
_root.onEnterFrame = function() {
if (s != undefined) {
trace(s);
delete this.onEnterFrame;
}
};
s2.swf
_root.s = 20; // <- will assign the s defined in s1.swf with the new value