Loader flash calls a function from the loaded flash

let’s imagine this scenario:
A.swf loads B.swf
after load is completed,A.swf needs to execute a function in B.swf called runCommands() for example.. here is the code for that (this is the code inside A.swf):

import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.*;
import flash.net.URLRequest;

...

var loaderRequest:URLRequest = new URLRequest("B.swf");
var movieLoader:Loader = new Loader();
movieLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
movieLoader.load(loaderRequest)....

function completeHandler(_event:Event)
{

	var _loaderInfo:LoaderInfo = _event.target as LoaderInfo;
	var loadedObject:Object = _loaderInfo.content;
	loadedObject.runCommands()
}
This entry was posted in Actionscript 3.0, Code Snippets. Bookmark the permalink.

2 Responses to Loader flash calls a function from the loaded flash

  1. Diego says:

    Thank you!

    …but I have the opposite problem :)

    I’d want to call a function in A from B.

    Are you able to do it? thanks!

  2. slaughter says:

    thanks !

    i was looking for what data type the loaded object was. (var loadedObject)
    turns out its an object. i was tryingeverything but
    Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>