[flexcoders] Type coercion failed for the same class

2010-03-17 Thread cosmin
Hello all. This is a problem in Flash, actually, not Flex, but i think
it might behave the same in Flex. Here's the scenario:
I have 4 SWF files: main.swf, platform.swf, pluginLoader.swf and
plugin.swf. pluginLoader.FLA and plugin.FLA are in the same folder, and
share some of the classes. At this point, they only share a PluginEvent
class. The flow is this: main.swf loads platform.swf; platform.swf loads
pluginLoader.swf; pluginLoader.swf loads the plugin.swf and here the
crazy stuff begins:
1. plugin.swf adds a listener for a PluginEvent event
2. pluginLoader.swf dispatches a PluginEvent event (both swf files use
the same file, from the same namespace)
3. Type coercion failed error occures.

One fix I found was to specifi the application domain when using
loader.load, and use ApplicationDomain.currentDomain, but that's not
working. Here's the loading code:

var pluginLoaderContext:LoaderContext = new LoaderContext();
pluginLoaderContext.applicationDomain = new
ApplicationDomain(ApplicationDomain.currentDomain);
var mRequest:URLRequest = new URLRequest(pluginURL);
pluginLoader.load(mRequest, pluginLoaderContext);

To top it off, if the pluginLoader.swf and plugin.swf are on the same
domain, everything works. If they're on different domains, the type
coercion appears. Should I use another ApplicationDomain? Any help would
be appreciated.


Re: [flexcoders] Type coercion failed for the same class

2010-03-17 Thread Alex Harui
See the modules presentation on my blog.


On 3/17/10 9:37 AM, cosmin flashcrow2...@yahoo.com wrote:






Hello all. This is a problem in Flash, actually, not Flex, but i think it might 
behave the same in Flex. Here's the scenario:
I have 4 SWF files: main.swf, platform.swf, pluginLoader.swf and plugin.swf. 
pluginLoader.FLA and plugin.FLA are in the same folder, and share some of the 
classes. At this point, they only share a PluginEvent class. The flow is this: 
main.swf loads platform.swf; platform.swf loads pluginLoader.swf; 
pluginLoader.swf loads the plugin.swf and here the crazy stuff begins:
1. plugin.swf adds a listener for a PluginEvent event
2. pluginLoader.swf dispatches a PluginEvent event (both swf files use the same 
file, from the same namespace)
3. Type coercion failed error occures.

One fix I found was to specifi the application domain when using loader.load, 
and use ApplicationDomain.currentDomain, but that's not working. Here's the 
loading code:

var pluginLoaderContex! t:LoaderContext = new LoaderContext();
pluginLoaderContext.applicationDomain = new 
ApplicationDomain(ApplicationDomain.currentDomain);
var mRequest:URLRequest = new URLRequest(pluginURL);
pluginLoader.load(mRequest, pluginLoaderContext);

To top it off, if the pluginLoader.swf and plugin.swf are on the same domain, 
everything works. If they're on different domains, the type coercion appears. 
Should I use another ApplicationDomain? Any help would be appreciated.





--
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs.adobe.com/aharui