Loading External SWF with Packager for iPhone
This is not a very technical post but one to show that it is possible to load SWFs in iOS applications. Any actionscript in the SWF will not execute, my example is just a simple animated SWF. In this code example I have one SWF with a animated vector over 20 frames. I published it and put it next to my local project to be packaged up in the ipa and also put a copy on at renaun.com to test loading remotely.
Here is the source files on github.
Here is the application test file that loads an animated SWF called ExternalAnimatedSWF.swf
:
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.net.URLRequest;
public class PFIExternalSWFTest extends Sprite
{
public function PFIExternalSWFTest()
{
init();
}
private var loaderLocal:Loader;
private var loaderRemote:Loader;
private function init():void
{
loaderLocal = new Loader();
loaderLocal.load(new URLRequest("ExternalAnimatedSWF.swf"));
loaderLocal.x = 10;
loaderLocal.y = 10;
addChild(loaderLocal);
loaderRemote = new Loader();
loaderRemote.load(new URLRequest("http://renaun.com/flex4/ExternalAnimatedSWF.swf"));
loaderRemote.x = 60;
loaderRemote.y = 60;
addChild(loaderRemote);
}
}
}
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.net.URLRequest;
public class PFIExternalSWFTest extends Sprite
{
public function PFIExternalSWFTest()
{
init();
}
private var loaderLocal:Loader;
private var loaderRemote:Loader;
private function init():void
{
loaderLocal = new Loader();
loaderLocal.load(new URLRequest("ExternalAnimatedSWF.swf"));
loaderLocal.x = 10;
loaderLocal.y = 10;
addChild(loaderLocal);
loaderRemote = new Loader();
loaderRemote.load(new URLRequest("http://renaun.com/flex4/ExternalAnimatedSWF.swf"));
loaderRemote.x = 60;
loaderRemote.y = 60;
addChild(loaderRemote);
}
}
}
Make sure to include the SWF file in the PFI’s command arguments to bundle it with the ipa.