我在某种程度上在Flex 3中创建了一个堆栈溢出...我试图从模态对话窗口中获取数据:

主要应用:

var myPopup:MyPopup;

function buttonClick( event:MouseEvent ):void
{
myPopup = MyPopup( PopUpManager.createPopUp( this, MyPopUp, true ) );
myPopup.addEventListener( CloseEvent.CLOSE, handler, false, 0, true );
}

function handler():void
{
//get data
}

MyPopup:

function buttonHandler( MouseEvent:event ):void
{
PopUpManager.remove( this );
this.dispatchEvent( new CloseEvent( CloseEvent.CLOSE ) );
}

如果这是不正确的,那么以允许我在对象上使用和检索数据的方式处理弹出窗口关闭的正确方法是什么?

有帮助吗?

解决方案

也许您可以尝试将事件参数添加到处理程序中。我不太确定ActionScript总能容忍没有提供。例如:

function handler(event:CloseEvent):void {
    // Handle away
}

我也是在解除Justin提到的弹出窗口之前调用处理程序的做法。

其他提示

我已经重新创建了你的代码,它对我来说很好用:(这意味着要么我误解了你的问题,要么错误是代码中的其他地方。

您是否有机会发布有关此问题的更多详细信息?

萨姆

PS以下是我用来测试的代码:

Application.mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

    <mx:Button x="10" y="10" label="Button" click="buttonClick(event)" id="popupButton"/>

    <mx:Script>
        <![CDATA[
            import mx.core.IFlexDisplayObject;
            import mx.managers.PopUpManager;

            private var popup:Popup;

            private function buttonClick(e:MouseEvent):void {
                popup = PopUpManager.createPopUp(this, Popup, true) as Popup;
                popup.addEventListener(Event.CLOSE, popupClose, false, 0, true);
            }

            private function popupClose(e:Event):void {
                trace(popup);
                popupButton.label = "Closed";
            }
        ]]>
    </mx:Script>

</mx:Application>

Popup.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
    <mx:Button x="167" y="123" label="Close me" click="buttonClick(event)"/>

    <mx:Script>
        <![CDATA[
            import mx.managers.PopUpManager;

            private function buttonClick(e:MouseEvent):void {
                dispatchEvent(new Event(Event.CLOSE));
                PopUpManager.removePopUp(this);
            }
        ]]>
    </mx:Script>

</mx:Canvas>

您还需要在弹出窗口中创建一个清除事件,模型等的dispose函数。否则,它不会被垃圾收集并减慢您的应用程序。

在您的示例中,将 PopUpManager.removePopUp(this); 移动到close事件处理程序,即 popupClose(e:Event)。您还需要使用弹出窗口替换参数 this

不完全确定PopUpManager的行为方式,但您可能想要在buttonHandler中切换语句:

function buttonHandler(MouseEvent:event):void
{
    this.dispatchEvent(new CloseEvent(CloseEvent.CLOSE));
    PopUpManager.remove(this);
}

当您的事件代码正在运行时,弹出窗口会保持不变,但是在您触发尝试从中获取数据的代码之前,它应该处理弹出对象处理的情况。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top