<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="onCreationComplete()"
>
<mx:Script>
<![CDATA[
import net.AirInstallAndLauncher;
private var installer :AirInstallAndLauncher = new AirInstallAndLauncher();
@param
private function onCreationComplete(event :Event = null) :void
{
if(Application.application.parameters != null)
{
if(Application.application.parameters["targetAirURL"] != undefined)
{
this.installer.targetAirURL = Application.application.parameters["targetAirURL"];
}
if(Application.application.parameters["runtimeVersion"] != undefined)
{
this.installer.runtimeVersion = Application.application.parameters["runtimeVersion"];
}
if(Application.application.parameters["appicationID"] != undefined)
{
this.installer.appicationID = Application.application.parameters["appicationID"];
}
if(Application.application.parameters["publisherID"] != undefined)
{
this.installer.publisherID = Application.application.parameters["publisherID"];
}
if(Application.application.parameters["arguments"] != undefined)
{
this.installer.arguments = (Application.application.parameters["arguments"] as String).split(",");
}
}
this.installer.addEventListener(Event.INIT, installerOnInit);
this.installer.init();
}
@param
private function installerOnInit(event :Event) :void
{
if(this.installer.status == AirInstallAndLauncher.STATUS_APPLICATION_INSTALLED)
{
this.installButton.label = "インストール済みのAIRアプリケーションを起動";
this.installButton.enabled = true;
}
else if(this.installer.status == AirInstallAndLauncher.STATUS_APPLICATION_NOT_INSTALL)
{
this.installButton.label = "AIRアプリケーションをインストール";
this.installButton.enabled = true;
}
else if(this.installer.status == AirInstallAndLauncher.STATUS_RUNTIME_NOT_INSTALL)
{
this.installButton.label = "AIRランタイムも含めてインストール";
this.installButton.enabled = true;
}
else if(this.installer.status == AirInstallAndLauncher.STATUS_RUNTIME_UNAVAILABLE)
{
this.installButton.label = "AIRをインストールできない環境です";
}
else if(this.installer.status == AirInstallAndLauncher.STATUS_AIR_SWF_IO_ERROR)
{
this.installButton.label = "入出力エラーが発生しました";
}
}
@param
private function installButtonOnClick(event :Event = null) :void
{
if(this.installer.status == AirInstallAndLauncher.STATUS_APPLICATION_INSTALLED)
{
this.installer.launchApplication();
}
else if((this.installer.status == AirInstallAndLauncher.STATUS_APPLICATION_NOT_INSTALL))
{
this.installer.installApplication();
}
else if(this.installer.status == AirInstallAndLauncher.STATUS_RUNTIME_NOT_INSTALL)
{
this.installer.installApplication();
}
else
{
throw new Error("このステータスではボタンが押せないはず。status=" + this.installer.status);
}
}
]]>
</mx:Script>
<mx:Button id="installButton"
label="初期化中・・・"
enabled="false"
click="installButtonOnClick()"
/>
</mx:Application>
package net
{
import flash.display.Loader;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.HTTPStatusEvent;
import flash.events.IOErrorEvent;
import flash.net.URLRequest;
@eventType
[Event(name="init", type="flash.events.Event")]
public class AirInstallAndLauncher extends EventDispatcher
{
public static const AIR_SWF_URL :String = "http://airdownload.adobe.com/air/browserapi/air.swf";
public static const DEFAULT_RUNTIME_VERSION :String = "1.1";
public static const STATUS_BEFORE_INIT :String = "0";
public static const STATUS_APPLICATION_INSTALLED :String = "1";
public static const STATUS_APPLICATION_NOT_INSTALL :String = "2";
public static const STATUS_RUNTIME_NOT_INSTALL :String = "3";
public static const STATUS_RUNTIME_UNAVAILABLE :String = "4";
public static const STATUS_AIR_SWF_IO_ERROR :String = "5";
public var targetAirURL :String = null;
public var runtimeVersion :String = DEFAULT_RUNTIME_VERSION;
public var appicationID :String = null;
public var publisherID :String = null;
public var arguments :Array = new Array();
protected var airSwf :Object;
protected var airSwfLoader :Loader = null;
protected var _status :String = STATUS_BEFORE_INIT;
public function init() :void
{
if((this.targetAirURL == null) || (this.targetAirURL == ""))
{
throw new Error("インストール対象のAIRアプリケーションのAIRファイルのURLが指定されていません");
}
if((this.appicationID == null) || (this.appicationID == ""))
{
throw new Error("インストール対象のAIRアプリケーションのアプリケーションIDが指定されていません");
}
if((this.publisherID == null) || (this.publisherID == ""))
{
throw new Error("インストール対象のAIRアプリケーションのパブリッシャーIDが指定されていません");
}
this.airSwfLoader = new Loader();
this.airSwfLoader.contentLoaderInfo.addEventListener(Event.INIT, onAirSwfLoaderInit);
this.airSwfLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onAirSwfLoaderErrorHandler);
this.airSwfLoader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, onAirSwfLoaderHttpStatus);
airSwfLoader.load(new URLRequest(AIR_SWF_URL));
}
public function installApplication() :void
{
if((this._status != STATUS_APPLICATION_NOT_INSTALL) && (this._status != STATUS_RUNTIME_NOT_INSTALL))
{
throw new Error("ステータスが不正です:" + this._status);
}
this.airSwf.installApplication(this.targetAirURL, this.runtimeVersion, this.arguments);
}
public function launchApplication() :void
{
if(this._status != STATUS_APPLICATION_INSTALLED)
{
throw new Error("ステータスが不正です:" + this._status);
}
this.airSwf.launchApplication(this.appicationID, this.publisherID, this.arguments);
}
@return
public function get status() :String
{
return this._status;
}
@param
protected function onAirSwfLoaderInit(event :Event) :void
{
this.airSwf = event.target.content;
var runtimeStatus :String = this.airSwf.getStatus();
if(runtimeStatus == "installed")
{
this.airSwf.getApplicationVersion(this.appicationID, this.publisherID, versionDetectCallback);
}
else if(runtimeStatus == "available")
{
this._status = STATUS_RUNTIME_NOT_INSTALL;
super.dispatchEvent(new Event(Event.INIT));
}
else
{
this._status = STATUS_RUNTIME_UNAVAILABLE;
super.dispatchEvent(new Event(Event.INIT));
}
}
@param
protected function onAirSwfLoaderErrorHandler(event :Event) :void
{
this._status = STATUS_AIR_SWF_IO_ERROR;
super.dispatchEvent(new Event(Event.INIT));
}
@param
protected function onAirSwfLoaderHttpStatus(event :HTTPStatusEvent) :void
{
if(event.status == 404)
{
onAirSwfLoaderErrorHandler(event);
}
}
@param
protected function versionDetectCallback(version :String) :void
{
if(version == null)
{
this._status = STATUS_APPLICATION_NOT_INSTALL;
}
else
{
this._status = STATUS_APPLICATION_INSTALLED;
}
super.dispatchEvent(new Event(Event.INIT));
}
}
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="AC_OETags.js" language="javascript"></script>
<style>
body { margin: 0px; overflow:hidden }
</style>
<script language="JavaScript" type="text/javascript">
</script>
</head>
<body scroll="no">
<script language="JavaScript" type="text/javascript">
</script>
<noscript>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="AirLauncherSample" width="100%" height="100%"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="AirLauncherSample.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#869ca7" />
<param name="allowScriptAccess" value="sameDomain" />
<embed src="AirLauncherSample.swf" quality="high" bgcolor="#869ca7"
width="100%" height="100%" name="AirLauncherSample" align="middle"
play="true"
loop="false"
quality="high"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</object>
</noscript>
</body>
</html>