Forums: Flash:

 

AS 3 External swf function

first
 

blacksanta_69 AS 3 External swf function

I can't figure out how to fire a function that's in an external swf loaded into a parent movie. Can anyone give me a hand?

 

Arsis

Wavey

You need to use LoaderInfo

In your main swf:

function loadExternal( ):void {
var ldr:Loader = new Loader();
ldr.contentLoaderInfo.addEventListener( Event.COMPLETE, onComplete );
ldr.load( new URLRequest( "external.swf" ) );
}
function onComplete( e:Event ):void {
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
addChild(e.target.content);
var swf:Object = loaderInfo.content;
swf.test( "yay!" );
}
loadExternal( );


In your external swf:

function test( msg:String ):void {
trace("success: " + msg);
}

 

blacksanta_69

Thanks Arsis. It was the ".content" thing I couldn't get. I still find something very counter-intuitive and frustrating about AS 3. Exposure has not proven a good remedy yet - I keep finding old techniques I have to relearn. I can't wait for it to get easier all over again.

 

arigato

wow, long time no see! Pop by wfg & say hi sometime, eh?

 

JLM

Arsis I have been messing with loading recently and getting my head round aspects and would be interested in yours or anyones ideas in regard to...


Is this similar?


var loaderInfo:LoaderInfo = new LoaderInfo( e.target );



And is this

var ldr:Loader;
function loadExternal( ):void {
ldr = new Loader();
ldr.contentLoaderInfo.addEventListener( Event.COMPLETE, onComplete );
ldr.load( new URLRequest( "external.swf" ) );
}
function onComplete( e:Event ):void {
var swf:MovieClip = ldr.content;
addChild(swf);
swf.test( "yay!" );
}
loadExternal( );



 

pyrogen

Thanks Arsis big grin

was just messing with this very thing today.


 
first
 

Forums: Flash: AS 3 External swf function

 
New Post
 
You must be logged in to post