0 Replies Latest reply on Sep 10, 2007 3:27 AM by

    Dynamic Loading Issue

      Hi all,

      Im having a bit of an issue trying to load an external .swf file into a flex2 loader. The .swf file was created as a flex library (.swc) and then unzipped to get the .swf file out of it. It might make more sense to put some of the code up here so you have an idea of what im doing:

      --------------------------------------------------------------------
      MyClass.as
      --------------------------------------------------------------------

      Code:
      package demo.test
      {
      import mx.core.UIComponent;

      public class MyClass extends UIComponent
      {
      public function test():void
      {
      }
      }
      }
      --------------------------------------------------------------------

      I then compile that into a 'MyClass.swc' and extract the 'library.swf' contained inside it onto a web server, i would then like to dynamically load this .swf and create a dynamic instance of 'MyClass' inside the client. Heres the code that loads the .swf and creates the class instance

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

      Code:
      private var ldr:Loader = new Loader();

      public function loadClass():void
      {
      var url:String = " http://localhost/mysite/library.swf";
      var urlReq:URLRequest = new URLRequest(url);

      ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);

      var context:LoaderContext = new LoaderContext();
      context.applicationDomain = ApplicationDomain.currentDomain;

      ldr.load(urlReq, context);
      }

      public function completeHandler(event:Event):void
      {
      var loadedClass:Class = ldr.contentLoaderInfo.applicationDomain.getDefinition("demo.test.MyClass") as Class;
      if (loadedClass != null)
      {
      var object:Object = new loadedClass;
      }
      }
      --------------------------------------------------------------------

      This doesnt seem to work and throws the following exception:
      --------------------------------------------------------------------

      Code:
      Error: Could not find resource bundle core
      at mx.resources::ResourceBundle$/getResourceBundle()[C:\dev\GMC\sdk\frameworks\mx\resources\ ResourceBundle.as:125]
      at mx.core::UIComponent$cinit()
      at global$init()[C:\dev\GMC\sdk\frameworks\mx\core\UIComponent.as:790]
      at global$init()
      at flash.system::ApplicationDomain/getDefinition()
      at MyLoadTest/completeHandler()
      --------------------------------------------------------------------

      With a little bit of playing about i worked out that if i stop MyClass from extending UIComponent then all works fine so im thinking that it has something to do with the flex framework not being initialized.

      Any ideas?

      If *anyone* could point me in the right direction or suggest a workaround id be indebted forever! (im at my wits end)

      Cheers,
      Ian