标题所说的。
我的本机代码中有:
freContext.dispatchStatusEventAsync("myEvent","");
在 ANE 的 AS3 部分中:
private static function onStatus( event:StatusEvent ):void {
if(event.code == MyEvent.EVENT_NAME){ // EVENT_NAME = "myEvent"
displayToast("dispatching event");
dispatcher.dispatchEvent(MyEvent(MyEvent.EVENT_NAME));
}
}
和我的弹性应用程序(MyAppHomeView.mxml(
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
title="Home View"
initialize="createListener()">
<fx:Script>
<![CDATA[
protected function createListener():void{
MyANE.showDialogMessage("init");
addEventListener(MyEvent.EVENT_NAME,handleEvent);
}
protected function handleEvent(event:MyEvent):void{
MyANE.showDialogMessage("myEvent");
}
]]>
</fx:Script>
</s:View>
我确实得到了"调度事件"吐司(这意味着本机代码部分工作正常(,但没有"myEvent"对话框。我做错了什么?
感谢 Organis 的评论和 Adobe 在这里的例子: https://github.com/nweber/SystemVolumeNativeExtension/blob/master/VolumeTest/src/VolumeTest.mxml 我设法解决了我的问题:
第一个 MyAne 类必须扩展 EventDispatcher。然后在 on状态 :
private function onStatus( event:StatusEvent ):void {
if(event.code == MyEvent.EVENT_NAME){ // EVENT_NAME = "myEvent"
displayToast("dispatching event");
dispatchEvent(new MyEvent(MyEvent.EVENT_NAME));
}
}
在 mxml 中,创建一个 MyANE 的实例并在其上调用 addEventListener。
<fx:Script>
<![CDATA[
var ane:MyANE = new MyANE();
protected function createListener():void{
MyANE.showDialogMessage("init");
ane.addEventListener(MyEvent.EVENT_NAME,handleEvent);
}
protected function handleEvent(event:MyEvent):void{
MyANE.showDialogMessage("myEvent");
}
]]>
</fx:Script>