• Flash/Flex Events: Error Removing Child with Custom Event

    So, I discovered yesterday that if you create a custom event with an event type name of “remove” that happens to also be associated with a call to removeChild() in any of your components, you will end up with the following error (some class names removed to avoid disclosure issues):

    TypeError: Error #1034: Type Coercion failed: cannot convert mx.events::FlexEvent@17977d31 to [your custom event name] at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.core::UIComponent/dispatchEvent()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\core\UIComponent.as:9051] at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::removingChild()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\core\Container.as:3307] at mx.core::Container/removeChild()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\core\Container.as:2261] at [code invoking the removeChild() event] at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.core::UIComponent/dispatchEvent()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\core\UIComponent.as:9051] at [code broadcasting the custom event] at [component broadcasting the call to create the custom event]

    Obviously, there is something in UIComponent on line 9051 (yikes! that class is stupid huge) that is causing an issue. I went in and looked at the code via the debugger, and the underlying issue is compiled in to a SWC that I couldn't see. I guessed that the name of the custom event was too generic, so I changed it to something that wasn't "remove", and the issue went away.

    Talk about leaky abstractions. :)

    Category: Uncategorized | Tags: