# ActionScript 3 Event Model Question

**URL:** <https://forum.kirupa.com/t/actionscript-3-event-model-question/205052>\
**Category:** flash\
**Created:** [October 25, 2006, 5:47pm UTC](https://forum.kirupa.com/t/actionscript-3-event-model-question/205052 "2006-10-25T17:47:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ytseshred](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ytseshred/32/2946_2.png) [@ytseshred](https://forum.kirupa.com/u/ytseshred)\
**Post date:** [October 25, 2006, 5:47pm UTC](https://forum.kirupa.com/t/actionscript-3-event-model-question/205052/1 "2006-10-25T17:47:59Z")

</div>

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:

```auto
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 — \*/

```auto
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.

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [October 25, 2006, 9:43pm UTC](https://forum.kirupa.com/t/actionscript-3-event-model-question/205052/2 "2006-10-25T21:43:46Z")

</div>

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.
