Jeff dePascale Blogging on and developing web and mobile technologies

Custom Events in loaded SWF files

Custom events that override the clone method of Event implemented in a loaded SWF file that has listeners in the parent or above will fail with a 1034 coercion error, even though the error seemingly says that the type it is coercing to is the same class type. After much searching I found the answer i needed - something i've come across before when building fosfr. I'm not entirely clear on why this only affects custom events with clone overriden and not others, but the solution is to import the custom event in the root document class and reference an instance of it, thereby forcing the root displayObject to include the event class in its compile. From that point forward it is accessible throughout the SWF hierarchy. You don't need to create an actual instance of the event, just reference it by name. Example:

package {
import my.custom.CustomEvent;

public class Main extends MovieClip {

CustomEvent;

pubic function Main(){
}
}
}

This is definitely required in Fosfr projects given the aformentioned use case. Note that it doesnt appear to cause issues when not listening down in the display list, like this case specifies. Listening up is fine, dispatching up is not.

Hopefully that'll save some of you the hour it took me to find that answer!

Share This
  • LinkedIn
  • Facebook
  • Twitter
  • Digg
  • del.icio.us
  • Google Bookmarks
  • StumbleUpon
  • Technorati
  • email