Question

I ran into a problem.I'm doing a GIS program using flex.

There's a map in my Application,when I click one icon on the map,windowA pops up,when I click a link inside windowA,windowB pops up,but here my problem coming out,when I close windowB and click the link inside windowA another time,Two windowB pop up...

In my windowA,I have

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

In WindowBControl,I have

addCommand(WindowBControl.EVENT_POPUPWindowB,WindowBCommand);

In WindowBCommand,I have

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

Could anyone give me a hand?

Much Thanks!

Best,Shuo

Was it helpful?

Solution

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.

OTHER TIPS

First

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

I think you have to somehow call PopupManager.removePopup because the Flex 3 ActionScript reference states:

Pops up a top-level window. It is good practice to call removePopUp() to remove popups created by using the addPopUp() method. If the class implements IFocusManagerContainer, the window will have its own FocusManager so that, if the user uses the TAB key to navigate between controls, only the controls in the window will be accessed

I find another solution.

In windowA's closing method,I write

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

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top