Skip to content

Instantly share code, notes, and snippets.

@matthua
Created April 12, 2013 10:27
Show Gist options
  • Save matthua/5371100 to your computer and use it in GitHub Desktop.
Save matthua/5371100 to your computer and use it in GitHub Desktop.
Externally hosting secondary swf files (iOS)
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
public class SampleMainSwf extends Sprite
{
private var externalLoader:Loader;
private var url:String= "http://www.xyz.com/Level1.swf";
private var urlRequest:URLRequest = new URLRequest(url);
private var ldrContext:LoaderContext;
public function SampleMainSwf()
{
externalLoader = new Loader();
externalLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);
externalLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,errorHandler);
ldrContext=new LoaderContext(false,ApplicationDomain.currentDomain,null);
try
{
externalLoader.load(urlRequest, ldrContext);
}
catch(e:Error)
{
trace("Error ID : "+e.errorID+"\nError Message : "+e.message);
}
}
private function completeHandler(e:Event):void
{
addChild(externalLoader);
}
private function errorHandler(e:IOErrorEvent):void
{
trace("In IO ErrorEvent Handler");
}
}
}
@matthua
Copy link
Author

matthua commented Apr 12, 2013

During IPA packaging, ADT extracts the Actionscript code from all child SWFs which are specified within the sample text file, adds it to the final executable and moves the stripped SWFs into the "externalStrippedSwfs" folder created in the current working directory. The directory structure within the "externalStrippedSwfs" folder remains the same as specified within the text file. The generated stripped SWF's can be externally hosted on a web server.
A working sample Actionscript code which loads a secondary swf derived using the above workflow, from an external server is as follows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment