1

我遇到了一个问题。我正在使用 flex 做一个 GIS 程序。

我的应用程序中有一张地图,当我单击地图上的一个图标时,会弹出窗口 A,当我单击窗口 A 内的链接时,会弹出窗口 B,但是我的问题出现了,当我关闭窗口 B 并单击窗口 A 内的链接时,另一个时间,两个windowB弹出...

在我的窗口A中,我有

...
var windowBEvt:WindowBEvent = new WindowBEvent();
CairngormEventDispatcher.getInstance().dispatchEvent(windowBEvt);
...
<control:WindowBControl id='control1'>

在 WindowBControl 中,我有

addCommand(WindowBControl.EVENT_POPUPWindowB,WindowBCommand);

在 WindowBCommand 中,我有

public function execute(event:CairngormEvent):void
{
    ...
    var windowB:WindowB = new WindowB();
    PopUpManager.addPopUp(windowB);
    ...
}

谁能帮我一把?

非常感谢!

最好的,硕

4

3 回答 3

1

Does WindowBControl inherit from FrontController? If so, you're probably instantiating it more than once on accident. This:

<control:WindowBControl id='control1'>

is going to create an instance of this front controller. Since you've put this line of code in WindowA, you're going to create a new instance of this controller every time you create a new instance of WindowA. This will then result in commands being called once for each instance of the controller every time your event fires.

You should only instantiate front controllers where you're positive they will only be instantiated a single time. The main application mxml is a good place for this.

于 2009-10-08T17:45:00.353 回答
1

第一的

// Shouldn't this be in a FrontController class?
addCommand(WindowBControl.EVENT_POPUPWindowB,WindowBCommand);

我认为您必须以某种方式调用 PopupManager.removePopup 因为 Flex 3 ActionScript 参考声明:

弹出一个顶层窗口。最好调用 removePopUp() 来删除使用 addPopUp() 方法创建的弹出窗口。如果该类实现了 IFocusManagerContainer,则窗口将拥有自己的 FocusManager,这样,如果用户使用 TAB 键在控件之间导航,则只会访问窗口中的控件

于 2009-10-08T03:18:44.123 回答
0

我找到了另一个解决方案。

在windowA的关闭方法中,我写

private function onClose():void
{
     PopUpManager.removePopUp(this);
     if(CairngormEventDispatcher.getInstance().hasEventListener(WindowBControl.EVENT_POPUPWindowB))
     {
         control1.removeCommand(WindowBControl.EVENT_POPUPWindowB);
     }

}
于 2009-10-10T05:15:06.630 回答