1

编码一个 Air Native 扩展:

您如何从 android 本机代码中分派一个事件,并让 ANE 的 actionscript 接口部分监听该事件并听到它?

我到处寻找,我似乎无法弄清楚这一点。

4

1 回答 1

2

as3部分

package com.yourpackage
{
    import flash.events.EventDispatcher;
    import flash.events.IEventDispatcher;
    import flash.events.StatusEvent;
    import flash.external.ExtensionContext;

    public class EventCaller extends EventDispatcher
    {
        private var context:ExtensionContext;

        public function EventCaller(target:IEventDispatcher=null)
        {
            super(target);      
            if(!context)
                context = ExtensionContext.createExtensionContext("com.yourpackage", null);
            if(context)
                context.addEventListener(StatusEvent.STATUS,statusHandle);
        }
        // listener function
        public function statusHandle(event:StatusEvent):void{
            trace(event);
            // process event data
        }

        public function requestEvent():void{
            context.call("requestEvent");
        }
    }
}

java部分(只是函数部分)

public class RequestEvent implements FREFunction {  

    @Override
    public FREObject call(FREContext context, FREObject[] args) {

               // dispatching event
               context.dispatchStatusEventAsync("someCode", "someLevel");

               Boolean value = true;               
               return FREObject.newObject(value);
        }
}
于 2013-04-29T17:29:10.630 回答