标题是什么。
我的原生代码:
freContext.dispatchStatusEventAsync("myEvent","");
在an3的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));
}
}
和我的flex应用程序(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>
我确实得到了&#34;调度事件&#34; toast(这意味着本机代码部分工作正常),但不是&#34; myEvent&#34;对话。我做错了什么?
答案 0 :(得分:0)
感谢Organis的评论和adobe的例子:https://github.com/nweber/SystemVolumeNativeExtension/blob/master/VolumeTest/src/VolumeTest.mxml我设法解决了我的问题:
首先,MyAne类必须扩展EventDispatcher。 然后在onStatus上:
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>