Reputation: 270
I am displaying external swf in an other swf. I read XML file that keeps external swf path. At some point I need the result of a function in the external one. So is it possible to pass the result and fetch it over URLRequest?
Here is the code:
var contentLoader:Loader;
var context:LoaderContext = new LoaderContext();
contentLoader = new Loader();
contentLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, contentLoadingCompleteActions);
contentLoader.load(new URLRequest(url), context);
url comes from XML parser as I said before. I want to load the swf and also get the selected variable if possible.
A (main swf) - imports swf via URLRequest
B (imported swf) - has to send a value to A
Upvotes: 0
Views: 56
Reputation: 7510
You can surely "communicate" between those two files. First, loader.contentLoaderInfo.content
is your actual loaded swf file. So you can call methods on it - either on the assigned class or on Timeline (not good). This way you can access properties or even functions:
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, contentLoadingCompleteActions);
loader.load(new URLRequest(url), context);
function contentLoadingCompleteActions(event:Event) {
// event.target is your loader
var swf = event.target.content as MovieClip; // or even cast to document class!
swf.getVariable(); // call method / get result
}
The same goes from the loaded swf - it can access it's parent AFTER it is added to stage (so it can have parent):
var parentObject:MovieClip = parent.parent as MovieClip; // or cast to document class
parentObject.callParentMethod();
You can cast to different classes (Object, Class, whatever you want) in order to communicate between them.
Upvotes: 1