PDA

View Full Version : Type Coercion failed: cannot convert MyEvent@12345 to MyEvent?



zeldalink
November 21st, 2009, 04:54 PM
I'm getting an error in an AS3 class that I found on a site,
which says that it cannot coerce MyEvent@12345 to MyEvent??

What could be wrong?

TypeError: Error #1034: Type Coercion failed: cannot convert com.box.services::SpeedEvent@7c055e1 to com.box.services.SpeedEvent
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunctio n()
at flash.events::EventDispatcher/dispatchEvent()
at com.box.services::ClientSpeed/::processReply()
at com.box.services::ServiceUtil$/onLoadCompleted()
at com.box.services::ClientSpeed/::onRequestCompleted()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunctio n()
at flash.events::EventDispatcher/dispatchEvent()
at com.box.services::ClientSpeedRequest/::onRequestCompleted()

-----------------------------------------------------------------------------------------------------

The funny part is I can't find the words "ClientSpeedRequest" or "ServiceUtil" anywhere in the entire source code folder! So I don't know where these classes / methods or whatever come from.

SpeedEvent is a class declared like this:

final public class SpeedEvent extends MapEvent
ClientSpeed is a class declared like this:

final public class ClientSpeed extends IClientSpeedWrapper implements IClientSpeed, IEventDispatcher

creatify
November 21st, 2009, 07:27 PM
can you post where / how you're dispatching the event and the event handler method? Seems to me that a different type of event passed to the handler that is expecting SpeedEvent - I'd be curious if you set that expected event within the handler to type MapEvent.

TheCanadian
November 21st, 2009, 08:21 PM
http://kirupa.com/forum/showthread.php?t=313070

wvxvw
November 22nd, 2009, 05:39 AM
This error means that the loading of external SWF has taken place and that second SWF was loaded into new application domain. These two SWFs, your and the loaded are allowed to communicate through the public API, like dispatching and handling events, but each has it's own copy of the MyEvent class. While coercing types player will consider those 2 classes as different, thus will give you error.
To avoid this you can: load SWF into parent application domain or into child application domain.
Parent application domain is: ApplicationDomain.currentDomain
Child domain is: new ApplicationDomain(ApplicationDomain.currentDomain)
Sometimes it is also possible to not load SWF into either of these domains and still avoid an error by registering class alias in both SWFs for the class in question, however, afaik, this only applies to AS objects obtained through SharedObject / LocalConnection / NetConnection or any other means of communication that rely on AMF serialization.