Search code examples
apache-flexcairngorm

Cairngorm XXXCommand be executed several times


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


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.