Adobe AIR - Load local SWF file using Htmlloader in ActionScript or HTML
Need to load local SWF file in Adobe AIR application using Htmlloader class, as local SWF file makes uses of classes such as ExternalInterface which needs webkit. Directory structure looks like
HelloWorld
├── HelloWorld-app.xml
├── HelloWorld.as
├── HelloWorld.swf
└── LocalSWF.swfHelloWorld.as
package {
import flash.display.Sprite;
import flash.html.HTMLLoader;
import flash.net.URLRequest;
import flash.filesystem.File;
import flash.display.Loader;
public class HelloWorld extends Sprite
{
public function HelloWorld()
{
var html:HTMLLoader = new HTMLLoader();
var urlReq:URLRequest = new URLRequest("LocalSWF.swf");
html.width = stage.stageWidth;
html.height = stage.stageHeight;
html.load(urlReq);
}
}
}HelloWorld-app.xml
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://ns.adobe.com/air/application/3.1">
<id>HelloWorld</id>
<versionNumber>0.1</versionNumber>
<filename>HelloWorld</filename>
<initialWindow>
<content>HelloWorld.swf</content>
<visible>true</visible>
<width>1000</width>
<height>1000</height>
</initialWindow>
</application>Compiling ActionScript to swf file using this command
~/flex_sdk_4.6/bin/amxmlc HelloWorld.asand HelloWorld.swf file gets created.
Running
~/flex_sdk_4.6/bin/adl HelloWorld-app.xmland nothing is getting displayed in application.
We can even make use of html or xml instead of ActionScript, only need is to load the local SWF file using Htmlloader.
