# Dispatching an Event in the Child and listen for in the Parent

**URL:** <https://forum.kirupa.com/t/dispatching-an-event-in-the-child-and-listen-for-in-the-parent/297683>\
**Category:** flash\
**Created:** [October 7, 2009, 3:51am UTC](https://forum.kirupa.com/t/dispatching-an-event-in-the-child-and-listen-for-in-the-parent/297683 "2009-10-07T03:51:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raabi](https://avatars.discourse-cdn.com/v4/letter/r/41988e/32.png) [@Raabi](https://forum.kirupa.com/u/Raabi)\
**Post date:** [October 7, 2009, 3:51am UTC](https://forum.kirupa.com/t/dispatching-an-event-in-the-child-and-listen-for-in-the-parent/297683/1 "2009-10-07T03:51:33Z")

</div>

Hello everybody

I have a dialogBox with 2 buttons - _ok\_btn_ and _cancel\_btn_. The code is in a Class - _testDialog_.

There are 2 issues:[LIST=1]  
[_]When any of the 2 buttons clicked, they dismiss the dialogBox without sending any alert to the parent (main time-line).  
[_]How to trap the clicked _buttonId_ in the parent.  
[/LIST]I have just an idea of the solution as _ **dispatching an event in the child and listen for that event in the parent** _. But, unfortunately, I don’t know how to go about it.

To make my point clear, here is the code:

```auto
 
package 
{
 import flash.display.*;
 import flash.events.*;
 public class TestDialog extends MovieClip 
 { 
  private var _btnSelected: String = "";
 
  public function TestDialog()
  {
   addEventListener(Event.ADDED_TO_STAGE, init);
  }
  private function init(e: Event): void
  {   
   ok_btn.addEventListener(MouseEvent.CLICK, ClickHandler);   
   cancel_btn.addEventListener(MouseEvent.CLICK, ClickHandler);
 
   removeEventListener(Event.ADDED_TO_STAGE, init);   
  }
  private function ClickHandler(e: MouseEvent): void
  {
trace("e.target.name: " + e.target.name);
   _btnSelected = e.target.name;
   parent.removeChild(this);
  }
 
  public function get BtnClicked(): String
  {
   return _btnSelected;
  }
 
  public function set BtnClicked(_str: String): void
  {
   _btnSelected = _str;
  }  
 }
}
 

```

The code in my FLA follows here:

```auto
 
var mc: TestDialog = new TestDialog();
addChild(mc);
//Here is my intention to do:
/*
if (btnClicked == ok_btn)
 proceed();
*/

```

I will highly appreciate a help, _with some added code_, to resolve this issue.
