Saturday, 5 January 2013

Access movie clip with SWF Loader

In one of my older post I wrote about loading external swf’s using the Greensock SWFLoader. Today I will post about accessing movie clips dynamically from externally loaded swf’s.

My example below assumes the external swf has a movie clip in the library with the ‘Export to Actionscript 3’ enabled and the Class name: MyMovieClip. The external swf has no content on the stage.

import com.greensock.loading.SWFLoader;

var loader:SWFLoader = new SWFLoader('example.swf',{name:'loader', onComplete:onCompleteHandler});

function onCompleteHandler(e:LoaderEvent):void
 var MyMovieClip:Class = loader.getClass('MyMovieClip');

 var myMc:MovieClip = new MyMovieClip();

From the code above I have loaded an external swf called example.swf. In the onComplete function I have used the getClass() method to get a reference to the class by name, and added the external movie clip on the stage.

To access externally loaded movie clips with native Actionscript 3 code. You can use the following code. I have used the applicationDomain.getDefinition() method to get a reference to the class by name.

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
loader.load(new URLRequest('example.swf'));

function loaded(e:Event):void
 var MyMovieClip:Class ='MyMovieClip') as Class;
 var myMc:MovieClip = new MyMovieClip();


  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP