Actor not forwarding events

jamesr's Avatar

jamesr

07 Aug, 2010 11:29 AM

This is less of a problem and more of an observation. If i have an Actor that forwards events from another class, if clone() is not overriden within the Event class that's being forwarded, it just fails silently and no event is dispatched.

protected function myEventHandler( event:MyEvent ):void
{

    dispatch( event );

}

I'm currently porting a project to RL that previously used the display list as an event bus, so it wasn't necessary to override clone within the custom events that were being bubbled. I realise this possibly isn't best practice, but never the less, without a clone method declared within the event, it just fails silently with RL without any error or warning,

  1. 1 Posted by creynders on 07 Aug, 2010 11:55 AM

    creynders's Avatar

    That's a flash player issue, not RL. From the AS3 help files:

    When creating your own custom Event class, you must override the inherited Event.clone() method in order for it to duplicate the properties of your custom class. If you do not set all the properties that you add in your event subclass, those properties will not have the correct values when listeners handle the redispatched event.

    Obviously this applies to the type property as well, therefore it fails silently; the event is redispatched, but the type property is empty.
    You should make it a custom to ALWAYS override the clone method of Event subclasses.

  2. 2 Posted by jamesr on 07 Aug, 2010 12:24 PM

    jamesr's Avatar

    true, but if you try to re-dispatch a custom Event object, doesn't it usually throw an Error if you haven't override the clone method?

  3. 3 Posted by jamesr on 07 Aug, 2010 01:26 PM

    jamesr's Avatar

    sorry, i realise i'm talking rubbish. The error's thrown when a handler that's expecting a certain event type receives an Event instead. This obviously wouldn't happen in RL as the the Event type is also checked.

  4. Stray closed this discussion on 10 Feb, 2011 05:33 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac