当我点击它时,我有一个按钮,一个popoup节目并要求确认。当它确认时,我发送和自定义事件。但在应用程序中我无法听取事件?有人可以帮帮我吗?
这也是一个移动应用程序。
第一个观点
<fx:Script>
<![CDATA[
import events.ConfirmDeleteEvent;
import mx.managers.PopUpManager;
private var _confirmDeletePopup:ConfirmDeletePopup;
protected function confirm(event:MouseEvent):void
{
this.addEventListener(ConfirmDeleteEvent.YES, deleteConfirm);
this.addEventListener(ConfirmDeleteEvent.NO, deleteNotConfirm);
_confirmDeletePopup = new ConfirmDeletePopup();
PopUpManager.addPopUp(_confirmDeletePopup, this, true);
PopUpManager.centerPopUp(_confirmDeletePopup);
}
protected function deleteConfirm():void
{
trace("delete confirm");
lbl.text = "Delete";
PopUpManager.removePopUp(_confirmDeletePopup);
}
protected function deleteNotConfirm():void
{
trace("delete not confirm");
lbl.text = "Don't delete";
PopUpManager.removePopUp(_confirmDeletePopup);
}
]]>
</fx:Script>
<s:Button width="100%" label="Delete" click="confirm(event)"/>
<s:Label id="lbl" width="100%" fontSize="36" text="What to do?" textAlign="center"/>
<fx:Script>
<![CDATA[
import events.ConfirmDeleteEvent;
import mx.managers.PopUpManager;
private var _confirmDeletePopup:ConfirmDeletePopup;
protected function confirm(event:MouseEvent):void
{
this.addEventListener(ConfirmDeleteEvent.YES, deleteConfirm);
this.addEventListener(ConfirmDeleteEvent.NO, deleteNotConfirm);
_confirmDeletePopup = new ConfirmDeletePopup();
PopUpManager.addPopUp(_confirmDeletePopup, this, true);
PopUpManager.centerPopUp(_confirmDeletePopup);
}
protected function deleteConfirm():void
{
trace("delete confirm");
lbl.text = "Delete";
PopUpManager.removePopUp(_confirmDeletePopup);
}
protected function deleteNotConfirm():void
{
trace("delete not confirm");
lbl.text = "Don't delete";
PopUpManager.removePopUp(_confirmDeletePopup);
}
]]>
</fx:Script>
<s:Button width="100%" label="Delete" click="confirm(event)"/>
<s:Label id="lbl" width="100%" fontSize="36" text="What to do?" textAlign="center"/>
在PopopUp中使用组件
我的活动
<fx:Script>
<![CDATA[
import events.ConfirmDeleteEvent;
import mx.managers.PopUpManager;
protected function click(type:String):void
{
var confirmDeleteEvent:ConfirmDeleteEvent = new ConfirmDeleteEvent(type);
var result:Boolean = dispatchEvent(confirmDeleteEvent);
trace("Event dispatch : " + result);
}
]]>
</fx:Script>
<s:VGroup paddingBottom="8" paddingLeft="8" paddingRight="8" paddingTop="8" width="100%">
<s:Label width="100%" maxDisplayedLines="5"
text="Delete?"
textAlign="center"/>
<s:HGroup width="100%">
<s:Button id="yesButton" width="50%" label="Yes" click="click(ConfirmDeleteEvent.YES)"/>
<s:Button id="noButton" width="50%" label="No" click="click(ConfirmDeleteEvent.NO)"/>
</s:HGroup>
</s:VGroup>
<fx:Script>
<![CDATA[
import events.ConfirmDeleteEvent;
import mx.managers.PopUpManager;
protected function click(type:String):void
{
var confirmDeleteEvent:ConfirmDeleteEvent = new ConfirmDeleteEvent(type);
var result:Boolean = dispatchEvent(confirmDeleteEvent);
trace("Event dispatch : " + result);
}
]]>
</fx:Script>
<s:VGroup paddingBottom="8" paddingLeft="8" paddingRight="8" paddingTop="8" width="100%">
<s:Label width="100%" maxDisplayedLines="5"
text="Delete?"
textAlign="center"/>
<s:HGroup width="100%">
<s:Button id="yesButton" width="50%" label="Yes" click="click(ConfirmDeleteEvent.YES)"/>
<s:Button id="noButton" width="50%" label="No" click="click(ConfirmDeleteEvent.NO)"/>
</s:HGroup>
</s:VGroup>
package events
{
import flash.events.Event;
谢谢
答案 0 :(得分:1)
将事件侦听器添加到_confirmDeletePopup组件,而不是调用组件。像这样:
protected function confirm(event:MouseEvent):void
{
_confirmDeletePopup = new ConfirmDeletePopup();
_confirmDeletePopup.addEventListener(ConfirmDeleteEvent.YES, deleteConfirm);
_confirmDeletePopup.addEventListener(ConfirmDeleteEvent.NO, deleteNotConfirm);
PopUpManager.addPopUp(_confirmDeletePopup, this, true);
PopUpManager.centerPopUp(_confirmDeletePopup);
}