Loading External swf and establishing Class Visiblity

I was creating a Flash 9 App for a client, the app was working fine. But, the client requested to the app to play a pre existing introduction.swf and then continue as before.

My strategy was to load a separate swf from the Main swf and then remove it when it had reached a certain point, and continue with the Main swf.

To implement this I used the Flash 9 Loader class and the ExternalMovie Class.

The Main Document Class loads the introduction.swf by the calls:

loader = new Loader();

var urlRequest:URLRequest=new URLRequest(“introduction.swf”);

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);

loader.load(urlRequest);

The onCompleteHandler() Method assigns the clip var and adds it to the DisplayList, and establishes a reference with the swf:Object instance, so the events can be listened to.

private function onCompleteHandler(loadEvent:Event) : void{

clip = loadEvent.currentTarget.content;

addChild(clip);

var loaderInfo:LoaderInfo = loadEvent.target as LoaderInfo;

var swf:Object = loaderInfo.content;

swf.addEventListener(Event.COMPLETE, onIntroCompleteHandler);

}

The swf to be loaded has it’s Document Class set to ExternalMove. When the introduction.swf reaches a certain from it calls a method animationComplete(). The animationComplete() method dispatches an Event.COMPLETE.

This is the Event which the Main Document Class is waiting for, and the onIntroCompleteHandler() Method is called, which removes the introduction.swf and continues with the Main Movie.

private function onIntroCompleteHandler(event:Event):void{

removeChild(clip);

loadMcg(); // continues with Main Movie

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s