ログインとログアウトに関する 2 つのイベントを発生させるプロジェクトのネイティブ拡張機能を構築しました。
private static const API_LOGIN_CALL:String = "LogIn";
private static const API_LOGOUT_CALL:String = "LogOut";
private static const EXTENSION_ID:String = "NdPlatformExt";
public var extContext:ExtensionContext;
private static var extIntance:NdPlatformExtension = null;
public function NdPlatformExtension()
{
extContext = ExtensionContext.createExtensionContext(EXTENSION_ID,"");
extContext.addEventListener(StatusEvent.STATUS,onEvent);
}
public static function get ExtInstance():NdPlatformExtension {
if(extIntance == null) {
extIntance = new NdPlatformExtension();
}
return extIntance;
}
public function onEvent(e:StatusEvent):void {
ConsoleLog(e.code);
switch(e.code)
{
case NdPlatformEvent.EVENT_API_LOGIN_RESULT:
{
ConsoleLog("event dispatch start");
var _succed:Boolean = dispatchEvent(new NdPlatformEvent(NdPlatformEvent.EVENT_API_LOGIN_RESULT,e.level.split('|')));
_succed = dispatchEvent(new NdPlatformEvent(NdPlatformEvent.EVENT_API_TEST,null));
ConsoleLog(_succed);//i've been checked on the log the _succed is true
}
break;
default:
{
dispatchEvent(new NdPlatformEvent(NdPlatformEvent.EVENT_API_LOGIN_RESULT,null));
}
break;
}
}
public function LogIn():String {
var _result:String = "";
try
{
_result = extContext.call(API_LOGIN_CALL) as String;
}
catch(_e:Error)
{
_result = _e.message;
}
return _result;
}
public function LogOut():String {
var _result:String = "";
try
{
_result = extContext.call(API_LOGOUT_CALL) as String;
}
catch(_e:Error)
{
_result = _e.message;
}
return _result;
}
}
}
カスタム イベントをリッスンするテスト フレックス プロジェクトをビルドしますが、追加したすべてのリスナーが起動しません。ここでビュー ファイルの内容、リスナーはビューの作成完了に追加します。
...creationComplete="init()" title="Test">
<fx:Script>
<![CDATA[
import NdPlatformExt.NdPlatformEvent;
import NdPlatformExt.NdPlatformExtension;
import flash.events.Event;
private var ext:NdPlatformExtension = new NdPlatformExtension();
protected function button1_clickHandler(event:MouseEvent):void
{
ext.LogIn();
}
protected function button2_clickHandler(event:MouseEvent):void
{
}
public function init():void
{
ext.addEventListener(NdPlatformEvent.EVENT_API_LOGIN_RESULT,onLoginResult,true);
ext.addEventListener(NdPlatformEvent.EVENT_API_TEST,onTest,true);
}
public function onLoginResult(_event:NdPlatformEvent):void{
ext.ConsoleLog("event receive ok");
ext.LogOut();
}
public function onTest():void{
ext.ConsoleLog("test receive ok");
}
]]>
</fx:Script>
<fx:Declarations>
</fx:Declarations>
<s:Label id="output" x="14" y="70" width="300" height="32" text=""/>
<s:Button x="44" y="19" width="231" label="Login"
click="button1_clickHandler(event)" alignmentBaseline="ideographicCenter"/>
<s:Button x="44" y="111" width="231" label="Purchase"
click="button2_clickHandler(event)" alignmentBaseline="ideographicCenter"/>
しかし、私が追加したすべてのリスナーは発火していません。