Custom events with parameters

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


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.



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 :

 Call to a possibly undefined method dispatchEvent.

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


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