有介紹到ANE中AS3如何呼叫Android原生功能的基本做法,
而這次會介紹的為如何由原生功能透過ANE來呼叫AS3.
想要呼叫回AS3需透過
dispatchStatusEventAsync( String code, String level )下面依照 Part 2 為例來修改,增加關閉確認視窗後的callback.
AlertFREFunction.java
package extension.myfirstandroidane;
import android.app.AlertDialog;
import android.content.DialogInterface;
import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREObject;
public class AlertFREFunction implements FREFunction {
@Override
public FREObject call(final FREContext freContext, FREObject[] freObjects) {
String title = "title";
String alertMessage = "alertMessage";
String buttonLabel = "ok";
try {
alertMessage = freObjects[0].getAsString();
title = freObjects[1].getAsString();
} catch (Exception e) {
}
new AlertDialog.Builder(freContext.getActivity())
.setTitle(title)
.setMessage(alertMessage)
.setPositiveButton(buttonLabel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
freContext.dispatchStatusEventAsync("close alert", "onComplete");
}
}).show();
return null;
}
}
AndroidAlert.as
package zpl.extension
{
import flash.events.StatusEvent;
import flash.external.ExtensionContext;
public class AndroidAlert
{
private static var _instance:AndroidAlert;
public static function get instance():AndroidAlert
{
if(_instance == null)
{
_instance = new AndroidAlert();
}
return _instance;
}
private var _extension:ExtensionContext;
private var _callback:Function;
public function AndroidAlert()
{
_extension = ExtensionContext.createExtensionContext( "zpl.ane.alert", "" );
}
public function show(msg:String,title:String,callback:Function):void
{
_callback = callback;
_extension.call("alertDialog",msg,title);
}
private function onStatus(e:StatusEvent):void
{
switch (e.level)
{
case "onComplete":
if (_callback != null)
{
_callback(); // e.code = "close alert"
_callback = null;
}
break;
default:
}
}
}
}
參考資料Adobe Flash Platform * FREContext
感謝您的技術分享 請問您還會製作新版flashDevelop的繁體中文化嗎
回覆刪除感謝支持喔,已經放上最新版了
刪除感謝您^^~
刪除