Reputation: 38180
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!
Upvotes: 3
Views: 970
Reputation: 113
The bubbling of events does not occur in the object that is receiving the event, but in the object that make the dispatch. Or to be precise, the event is bubbling through all the ancestors of the dispatching object. So you don't have to worry about that.
And also, you are already receiving a CustomEvent
in your onCustomEventType
-function, so there is no need to cast it.
Upvotes: 1
Reputation: 4870
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.
Upvotes: 8