Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate Plugins in Flex - loading nested SWF files
    primarykey
    data
    text
    <p>I'm trying to implement a plugin system for our application, and having a devil of a time getting SWF file which was dynamically loaded itself, load additional SWF files.</p> <p>It goes something like this:</p> <ol> <li>Main Application Shell loads...</li> <li>---------+ Application loads...</li> <li>-----------------+Plugin(s)</li> </ol> <p>I have no problem getting app #1 to load app #2</p> <p>However, try as I might, I cannot get app #2 to load and instantiate #3</p> <p>I've tried various permutations using the ModuleManager, but this is the closest I get. When the onLoadComplete method get invoked, I can see that the SWF loaded, however the factory always returns NULL.</p> <p>What is interesting is that when I extract this out in its own application, it works fine. This issue is triggered by the fact that I'm loading Plugin from a SWF that was loaded dynamically itself.</p> <p>I believe this is due to the <code>ApplicationDomain</code>, but I cannot make heads or tails of it. I tried specifying <code>currentDomain</code>, <code>new ApplicationDomain(Application.currentDomain)</code> and <code>new ApplicationDomain()</code> without success. </p> <p>Also, it is important to note that I cannot make reference a hard reference to the Foo class in either applications since by their nature, we will not know ahead of time what they will contain.</p> <p>Googlin' around, this seems to be a fairly known problem, but I have not found a (clear) solution yet.</p> <pre><code>. . . assetModule = ModuleManager.getModule("Foo.swf"); assetModule.addEventListener(ModuleEvent.READY, onLoadComplete ); assetModule.addEventListener(ModuleEvent.ERROR, onLoadError); assetModule.load(); . . . private var _pluginInstance:Plugin; private function onLoadComplete( event:Event ):void { trace("module loaded"); _pluginInstance = assetModule.factory.create() as Plugin; if( _pluginInstance ) _pluginInstance.startup(); else Alert.show("unable to instantiate module"); } private function onLoadError( event:Event ):void { Alert.show("error"); } My Plugin looks like this: package { import mx.collections.ArrayCollection; import mx.modules.ModuleBase; public class Plugin extends ModuleBase public function startup():void { } . . . } </code></pre> <p>and</p> <pre><code>package { import Plugin; import mx.modules.ModuleBase; public class Foo extends Plugin { public function Foo() { trace("foo constructor invoked"); } override public function startup():void { trace("foo started"); } . . . } </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.
 

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