Running into a problem dispatching a custom event from a parent SWF made in Flex Builder to a child SWF made in Flash CS4 that is loaded at runtime. Namely, whenever the child SWF is dispatched an event, I get a runtime error:
TypeError: Error #1034: Type Coercion failed: cannot convert myPackage.myEvents::myCustomEvent@74a6741 to myPackage.myEvents.myCustomEvent.
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at myPackage.App::SendMessageToLoadedSWF()
The custom event is defined in a standalone library that both the flex project and the flash project link to staticly. I wanted to go this route so that as I add new types of events, I can rebuild the application and flash swfs and not have to worry about moving .as files around (lets hold off on RSL’s until I get this simple case worked out).
This error message makes it sound like the application defines a myCustomEvent at compile time, and the flash movie defines its own myCustomEvent when it is published. Then when the application is run, the myCustomEvent dispatched in the application doesn’t match the one in the flash swf. Now I thought that application domains were supposed to sort all of this out, where the child uses the parent’s definition for any classes that are duplicated. But when I load the child swf and use the current domain in the LoaderContext I still get the same error.
I’ve been digging around for solutions to this for a few hours, and I’ve already tried the following to no avail:
Make a dummy variable of myCustomEvent in both the application and the flash file. This doesn’t seem to have any effect, as both the application and the flash child can create myCustomEvents just fine.
Change the event handler in the Flash swf to take the parent class Event instead of myCustomEvent. This resolves the runtime error, but I can’t access any of the new data members I added to myCustomEvent without casting it first. And casting the event to myCustomEvent generates the same run time error. I can access the values using the bracket operators, but then I’ve given up compile time type checking and opening up all sorts of headaches later on.
I feel like I’m missing something very basic here, but after digging around for a few hours can’t seem to put my finger on it.
Thanks in advance!