Actionscript 3.0

Accessing methods within loaded swf

Recently I was working on an application which loads flash or flex swf in it. We had to access internal methods in the loaded swf, flash and flex generated swf required different ways to access.

Probably any one of you reading this may have a better way.

<!--?xml version="1.0" encoding="utf-8"?-->
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"&gt;
<![CDATA[
import mx.core.IUIComponent;
import mx.events.FlexEvent;
import mx.managers.SystemManager;

private var _systemManager:SystemManager;
private var _loadedApplication:IUIComponent;

private var _isFlexApp:Boolean = false;

protected function loader_completeHandler(event:Event):void{
try{
_systemManager = SystemManager(loader.content);

_systemManager.addEventListener(FlexEvent.APPLICATION_COMPLETE, appApplicationCompleteHandler);
_systemManager.addEventListener(FlexEvent.UPDATE_COMPLETE, appUpdateCompleteHandler);

_isFlexApp = true;
}catch(error:Error){
_isFlexApp = false;
}

}

private function appUpdateCompleteHandler(event:FlexEvent):void{
_loadedApplication = _systemManager.application;
}

private function appApplicationCompleteHandler(event:FlexEvent):void{
_loadedApplication = _systemManager.application;
}

private function callMethodHandler(event:MouseEvent):void{
if(_isFlexApp){
if((_loadedApplication as Object).hasOwnProperty("clearAll")){
(_loadedApplication as Object).clearAll();
}
}else{
if((loader.content as Object).hasOwnProperty("clearAll")){
(loader.content as Object).clearAll();
}
}

}
]]>

&nbsp;
Disclaimer: All published content views of author.