Search code examples
flashactionscript-3

How to redispatch a custom event to another class (not a parent) in Flash?


I cannot bubble the event because I want to send to another class that is not even a movieclip but a simple class.

So I transform previous source code here Is it impossible with Flash to get the Instance Creator? for

private function onCustomEventType(e:CustomEvent):void
{
    trace(e.value);
    //redispatch
    this.dispatchEvent(e as CustomEvent);

}// end function

error is

conversion of flash.events to CustomEvent impossible

Whereas I have casted to CustomEvent to be sure!


Solution

  • In your event handler you can dispatch the event again. But what happens then is that Flash Player clones the event that was received into a new one. When you have made your own custom events, you should therefore always override the clone() function. Otherwise you will get runtime errors such as the one you mentioned.

    in your case your CustomEvent class should have this method

        override public function clone():Event
        {
            return new CustomEvent(type, bubbles, cancelable);
        }
    

    and if your constructor needs additional parameters make sure to put them in there too.