Skip to content

Instantly share code, notes, and snippets.

@olafkrueger
Created April 24, 2018 08:59
Show Gist options
  • Save olafkrueger/017820407c79408226581e79853604ca to your computer and use it in GitHub Desktop.
Save olafkrueger/017820407c79408226581e79853604ca to your computer and use it in GitHub Desktop.
Loading swf at runtime
/***
* Taken from here:
* https://stackoverflow.com/questions/2713865/how-to-run-an-external-swf-inside-a-flex-application?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
*/
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="loadSwfApplication()">
<fx:Script>
<![CDATA[
private function loadSwfApplication():void {
// load the file with URLLoader into a bytearray
var loader:URLLoader=new URLLoader();
// binary format since it a SWF
loader.dataFormat=URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, onSWFLoaded);
//load the file
loader.load(new URLRequest("http://path/to/the/swf/superApp.swf"));
}
private function onSWFLoaded(e:Event):void {
// remove the event
var loader:URLLoader=URLLoader(e.target);
loader.removeEventListener(Event.COMPLETE, onSWFLoaded);
// add an Application context and allow bytecode execution
var context:LoaderContext=new LoaderContext();
context.allowLoadBytesCodeExecution=true;
// set the new context on SWFLoader
sfwLoader.loaderContext = context;
sfwLoader.addEventListener(Event.COMPLETE, loadComplete);
// load the data from the bytearray
sfwLoader.load(loader.data);
}
private function loadComplete(completeEvent:Event):void {
// var swfApplication:* = completeEvent.target.content;
}
]]>
</fx:Script>
<s:VGroup width="100%" height="100%">
<s:Label text="Loaded app:" />
<s:SWFLoader id="sfwLoader" width="100%" height="100%" />
</s:VGroup>
</s:WindowedApplication>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment