I’ve loaded an external swf using the following code…
this.myRequest = new URLRequest("test.swf");
this.myLoader = new Loader();
this.myLoader.load(this.myRequest);
this.oRender.addChildAt(this.myLoader, 4);
I want to execute a function in test.swf from the parent swf…
How can I do this? :ponder:
I had to change “this.myLoader.addEventListener(Event.COMPLETE, grabContent);” to " this.myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, grabContent);" to get it to work.
[quote=skineh;2292889]Technically, yes. Any way that you can delay your call to the external swf’s functions would be sufficient. Using an eventListener is best practice, however, since it ensures you’re tapping into the loader’s contents only after it has become available. That doesn’t mean you have to do everything inside that listener, though. Take the following for example.
var externalSwf:Object;
this.myRequest = new URLRequest("test.swf");
this.myLoader = new Loader();
this.myLoader.addEventListener(Event.COMPLETE, grabContent);
this.myLoader.load(this.myRequest);
this.oRender.addChildAt(this.myLoader, 4);
function grabContent(event:Event):void
{
externalSwf = event.target.content;
nextFunction();
}
function nextFunction():void
{
externalSwf.childMethod();
externalSwf.someProperty = 15;
}
Here, you’re only using the listener to assign the loader’s content to the externalSwf object. Now you can access externalSwf wherever you want. In the example I give, the listener assigns the value, then goes on to the next function to do whatever it is you see fit. :thumb:[/quote]