# Custom events with parameters

**URL:** <https://forum.kirupa.com/t/custom-events-with-parameters/331310>\
**Category:** Uncategorized\
**Created:** [July 3, 2013, 7:27pm UTC](https://forum.kirupa.com/t/custom-events-with-parameters/331310 "2013-07-03T19:27:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bonassus](https://avatars.discourse-cdn.com/v4/letter/b/ea5d25/32.png) [@bonassus](https://forum.kirupa.com/u/bonassus)\
**Post date:** [July 3, 2013, 7:27pm UTC](https://forum.kirupa.com/t/custom-events-with-parameters/331310/1 "2013-07-03T19:27:02Z")

</div>

I’m confused. I found this class online for passing parameters with custom events.

```auto

package 
{
    import flash.events.Event;
    public class CEvent extends Event
    {
        public static const CUSTOM_EVENT: String = "custom_event";
        
        public var data:Object;
        
        public function CEvent(type:String, data:Object, bubbles:Boolean=false, cancelable:Boolean=false)
        {
            super(type, bubbles, cancelable);
            this.data = data;
        }
        
        override public function clone():Event
        {
            return new CEvent(type, data, bubbles, cancelable);
        } 

    }
}

```

and then you are suposed to be able to dispatch the event and send an object with it.

```auto

dispatchEvent(new CEvent(CEvent.CUSTOM_EVENT, object));

```

i don’t understand how to use this. if i try to use the above dispatchEvent code from another class. i get :

```auto
 Call to a possibly undefined method dispatchEvent.

```

I normally use a custom events class that looks like this:

```auto

package
{
    import flash.events.Event;
    import flash.events.EventDispatcher;
    
    public class CustomEvents extends EventDispatcher
    {
        public static const CUSTOM_EVENT:String = 'Custom_Event';
        
        
        public function CustomEvents()
        {
        }
        
        
        public function custom_event():void{
            dispatchEvent(new Event(CUSTOM_EVENT));
        }
        
    }
}

```

so i instantiate this CustomEvents class wherever i want and the call the public function custom\_event on it. then i can listen for the event from another class that has a reference to the same instance. I don’t know if i’m going about this the hard way or not.

This [COLOR=#000000][FONT=arial]dispatchEvent(new CEvent(CEvent.CUSTOM\_EVENT, object));[/FONT][/COLOR] creates a new instance of the [FONT=arial][COLOR=#000000]CEvent class and then calles the custom\_event. but i don’t understand what this [/COLOR][/FONT][COLOR=#000000][FONT=arial]dispatchEvent function is being called on unless its being called from within the [/FONT][/COLOR][COLOR=#000000][FONT=arial]CEvent class which doesn’t seem very useful.  
[/FONT][/COLOR]  
if someone could help me out i would appreciate it.

thanks,

B
