开发者

Who should remove popup, calling app or popup itself?

Here is the scenario...I have an application that has an "Open" button. When you click the open button, a TitleWindow pops up (via the PopUpManager) a dialog that allows you to select a record. In that window, you can either click "Ok" once you've selected a record, or cancel the dialog which should close the window.

What is the best way to handle this, knowing I need to return the record number to the main application? Right now I have the main application opening up the custom TitleWindow. In the TitleWindow, I have an event that fires when the user clicks "Ok" and a record is selected. That's how the main application listens for the recordId. What I'm wondering is if I can do something like this:

private function RecordSelected():void
{
    this.selectedRecord = someControl.selectedIndex;

    this.dispatchEvent(new Event("RecordSelected"));

    PopUpManager.removePopup(this);
}

Will the instance of the TitleWindow stay active until after the event is handled by the main application, or could it be removed before the main application fully handles the event (thus ending with a null reference exception)?

Alternatively, is it better to close the window in the event handler like so:

private function titleWindow_RecordSelected(event:Event)
{
    var openDialog:CustomTitleWindow = CustomTitleWindow(e.currentTarget);

    this._selectedRecord = openDialog.selectedRecord;

    PopUpManager.removePopup(openDialog);
}

I'm also wondering if sending the selection out in an开发者_Go百科 event is the best way to do this also. Any insight would be appreciated. Thanks in advance.


What is the best way to handle this, knowing I need to return the record number to the main application?

Best is always subjective, but I usually handle closing of the window in the window component; and then dispatch an event with appropriate data (In this case Record No) back to the application. It sounds like your 90% there. Just instead of dispatching an event Event, create a custom Event class with your recordID. Then it won't matter if the pop up is still in memory or not when you need to use the record ID.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜