# Dispatching events help

**URL:** <https://forum.kirupa.com/t/dispatching-events-help/281196>\
**Category:** Uncategorized\
**Created:** [February 5, 2009, 10:56pm UTC](https://forum.kirupa.com/t/dispatching-events-help/281196 "2009-02-05T22:56:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![brian914](https://avatars.discourse-cdn.com/v4/letter/b/fbc32d/32.png) [@brian914](https://forum.kirupa.com/u/brian914)\
**Post date:** [February 5, 2009, 10:56pm UTC](https://forum.kirupa.com/t/dispatching-events-help/281196/1 "2009-02-05T22:56:56Z")

</div>

I am new to this and am trying to figure out how to dispatch events.

I want to dispatch an event on click of my buttons and have the following. What am I doing wrong? What is this not working?

Thank you very much for any help with this!

```auto

import mx.events.EventDispatcher;
import mx.utils.Delegate;

class HomeMain extends MovieClip
{
	//Button Variables
	private var home_btn0:MovieClip;
	private var home_btn1:MovieClip;
	private var numOfBtns:Number = 2;
	
	// Event Dispatcher
	public var dispatchEvent:Function;
	public var addEventListener:Function;	
	
	public function HomeMain(Void)
	{
		//Activate the buttons
		EventDispatcher.initialize(this);
		activateBtns();
	}
	
	private function activateBtns():Void 
	{
		//Activate the buttons
		for(var i:Number = 0; i < numOfBtns; i++)
		{
			var ref:MovieClip = this["home_btn" + i];
			ref.id = i;
			//Btn actions
			ref.onRelease = function():Void {
				trace(this.id);
				dispatchEvent({type:"itemClicked"});
			}
		}
		
		home_btn0.addEventListener("itemClicked", Delegate.create(this, onItemClick));
		home_btn1.addEventListener("itemClicked", Delegate.create(this, onItemClick));
	}
	
	private function onItemClick(e:Object):Void 
	{
		trace("I hope I get this to work");
	}
}

```
