PDA

View Full Version : from a loaded swf clip, access/reference variable in the mainTimeline


samlovesflash
01-14-2008, 06:55 PM
Hello all, want to ask you a question:

In the mainTimeLine, I have a string variable like this:

var myString:String="Hello!";

Now I load an external swf to the mainTimeline:

var ContentLoader:Loader=new Loader();
ContentLoader.load(new URLRequest("externalClip.swf"));

Now, I can pass the value of variable "myString" to the "ContentLoader.content", no problem.

My question is, if I am not passing the value to the loaded clip, can I use some script (within the loaded swf) to reference the "myString" in the main movie?

it seems to me now it's only one way street in AS3 - I have to pass that variable to the loaded swf, not the other way around... which means, I can't use the AScript in the loaded clip to control anything on the main timeline?

any thoughts?

Sam

G:String
01-14-2008, 08:21 PM
That's a problom I'm just looking to solve, although in my case I'm using classes. How, in peet's name, do you refer the ducoment class (it's like the main timeline) from other classes? I couldn't find a way so far.

Mazoonist
01-15-2008, 01:39 AM
Good news... it's not just a one-way street!

I'm attaching a simple example of a flash Actionscript 3.0 file that loads a SWF. The SWF contains a button, and you can click it to advance the main timeline of the file that did the loading. Hope it helps.

Edit: You can also read a variable that's defined in the main SWF from the loaded SWF. Add this line to the actions in the first frame of loader.fla:
var testVar:String = "Hello World";
Then add this line to the button's event handler function on frame 1 of loaded.fla:
trace(MovieClip(parent.parent).testVar);
The message "Hello World," which is stored in a string variable in the main timeline, will be traced when you click the button in the loaded SWF.

(Be aware that every time you change a fla file, you have to run it to generate a new SWF. So if you make changes and they don't seem to appear, the probable cause is that you forgot to "test movie").

samlovesflash
01-15-2008, 06:46 AM
Bananas!! This is great, thank you for sharing.

Cheers.

Sam

Good news... it's not just a one-way street!

I'm attaching a simple example of a flash Actionscript 3.0 file that loads a SWF. The SWF contains a button, and you can click it to advance the main timeline of the file that did the loading. Hope it helps.

Edit: You can also read a variable that's defined in the main SWF from the loaded SWF. Add this line to the actions in the first frame of loader.fla:
var testVar:String = "Hello World";
Then add this line to the button's event handler function on frame 1 of loaded.fla:
trace(MovieClip(parent.parent).testVar);
The message "Hello World," which is stored in a string variable in the main timeline, will be traced when you click the button in the loaded SWF.

(Be aware that every time you change a fla file, you have to run it to generate a new SWF. So if you make changes and they don't seem to appear, the probable cause is that you forgot to "test movie").

:)