Note that there are some explanatory texts on larger screens.

plurals
  1. POFlex "Type Coercion" error when casting to interface
    primarykey
    data
    text
    <p>This is the error I am getting in the <em>handleModuleReady</em> function:</p> <pre><code>[Fault] exception, information=TypeError: Error #1034: Type Coercion failed: can not convert MyModule@39b8479 to IModuleInterface. </code></pre> <p>I have an application setup and I have created modules to load at runtime in order to decrease the filesize (as most users will only ever need one of the modules).</p> <pre><code>&lt;!-- maker.mxml --&gt; &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute" creationComplete="init(event)"&gt; &lt;mx:Style source="css/maker.css" /&gt; &lt;mx:Script&gt; &lt;![CDATA[ //Modules import mx.events.ModuleEvent; import mx.modules.ModuleLoader; import mx.modules.ModuleManager; import mx.modules.IModuleInfo; private var info:IModuleInfo; ... private function init(e:Event):void { info = ModuleManager.getModule("MyModule.swf"); info.addEventListener("ready", handleModuleReady); info.addEventListener("error", handleModuleError); info.load(ApplicationDomain.currentDomain); } private function handleModuleReady(moduleEvent:ModuleEvent):void { var ichild:IModuleInterface = IModuleInterface(moduleEvent.target.factory.create()); if (ichild != null) { //call class functions here via ichild object } else { trace("Something has gone wrong."); } } ... &lt;/mx:Script&gt; ... </code></pre> <p>I have created the IModuleInterface class (IModuleInterface.as), and the MyModule.mxml file compiles without issue, but I continue to get the typecasting error despite trying a variety of potential solutions such as loading the module through ModuleLoader, ModuleManager, and most recently setting the applicationDomain.</p> <p>Please tell me if you know how to fix this. The rest of the internet doesn't. Trust me, I've looked.</p> <p>If relevant, the interface looks something like this.</p> <pre><code>//IModuleInterface.as package { public interface IModuleInterface { function getSomeClass():Class; function getSomeArray():Array; function getSomeInt():int; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload