3
votes

I am dispatching events from a child to a parent swf. It was working properly, until I used a preloader swf to load the parent, then the parent stopped getting events from the child. I get this error now:

TypeError: Error #1034: Type Coercion failed: cannot convert com.company.events::MyCustomEvent@22494251 to com.company.events.MyCustomEvent.
    at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()

What does that mean? And why does it only happen when I wrap the main swf in a loader? Thanks for any help - I'm desperate!

2

2 Answers

4
votes

Sounds like an ApplicationDomain issue.

Try something like this:

public function loadSWF(url:String):void 
{
    var req:URLRequest = new URLRequest(url);
    var cxt:LoaderContext = new LoaderContext();
        cxt.applicationDomain = ApplicationDomain.currentDomain;

    var ldr:Loader = new Loader();
        ldr.load(req, cxt);
}
1
votes

why does event handling break when wrapping the main swf in a loader?

It doesn't really "break"... it's more that methods and properties are namespaced for each swf so that there isn't a conflict in the event that you load a random swf - say an advert - into your shell app and mayhem ensues because events in the child are being caught by the parent as they travel up the display list.

It is kinda voodoo though, so don't worry about finding it confusing. You can find a good overview here.