ActionScript 3 Event Model Question

I think I understand the new Events model, but something isn’t occurring the way I think it should be.

I have a few custom control classes I’ve made that have menus, etc. which open when they are clicked, and I would like to close any open containers when the user clicks anywhere else in the flash player (an example: you right-click on the desktop to open the context menu, and then click outside of the menu to close it).

If I’m properly understanding the event model, I thought if you dispatched an event onto the stage, then Flash would walk down the display list of the stage checking to see if any objects in the list are listening to the event that was dispatched. I’ve setup my project to do this, but I’m not capturing the events in the inner classes.

An abstracted example of my class framework is something like this:

class CustomEvent extends Event {
 public static const STAGE_CLICK:String = "stage_click";

  public function CustomEvent(type:String) {
    super(type);
  }
  ... // remaining class definition
}

class OuterContainer extends Sprite { /* some stuff in this class */ }
class InnerContainer extends Sprite {
  public function InnerContainer() {
    this.addEventListener(CustomEvent.STAGE_CLICK, stageClicked);
  }

  private function stageClicked(evt:MouseEvent):void {
    trace("Caught STAGE_CLICK inside InnerContainer!");
  }
}

The stage actions of the timeline look like:

/* — TIMELINE ACTIONS — */

stage.addEventListener(MouseEvent.CLICK, stageClicked);

var oc:OuterContainer = new OuterContainer();
var ic:InnerContainer = new InnerContainer();

oc.addChild(ic);
stage.addChild(oc);

function stageClicked(evt:MouseEvent):void {
  trace("stage clicked!");
  stage.dispatchEvent(new CustomEvent(CustomEvent.STAGE_CLICK));
}

/* === TIMELINE ACTIONS === */

I would think that when a user clicks on the stage it would dispatch this event into the event flow, and check to see if any objects on the stage are listening to the STAGE_CLICK event. The InnerContainer class listens to this event when it is constructed, yet the event handling function within the InnerContainer isn’t being fired when I click on the stage.

Is there something I’m fundamentally missing? I know that it would fire if I would directly dispatch the event onto the InnerContainer instance of the class, but I don’t want to have to manually dispatch it onto every item on the stage.

I thought the new event model would allow what I’m trying to do, so if anyone has any suggestions/ideas please reply! Thanks.

Your InnerContainer instance must be a listener to the stage and not itself. Also, the stageClicked member of InnerClass recieves a CustomEvent as its argument, not a MouseEvent.