0 Replies Latest reply on Mar 29, 2012 3:41 PM by Federico Martin Satelier

    Dynamic Load SWC and Error Skin

    Federico Martin Satelier

      Hi all, I am creating an application that dynamically load and then intanciarSWC classes within.

       

      To load a SWC I do it this way:

       

               

                         var rawSWC:FZip = new FZip();

                                              rawSWC.addEventListener(Event.COMPLETE, swcLoaded);

                                              rawSWC.load(new URLRequest('URL'));

       

       

                private function swcLoaded(event:Event):void{

       

                                    event.target.removeEventListener(event.type, arguments.callee);

       

                                    var rawSWC:FZip = event.target as FZip;

       

                       //  this is our actual swf file in binary

                                    var codeSWF:FZipFile = rawSWC.getFileByName('library.swf');

       

                       //  we'll use the Loader class to unpack the swf...

                                    var l:Loader = new Loader();

                                    l.contentLoaderInfo.addEventListener(Event.COMPLETE, showWindow);

       

                       //  this is the magic! This tells the loader to bring the code in

                       //  the swf into our local code space instead of it's own little bubble

                                    var c:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);

                                    c.allowCodeImport = true;

       

                                    l.loadBytes(codeSWF.content, c);

                          }

       

                          private function showWindow(event:Event):void{

                                    if(event != null)event.target.removeEventListener(event.type, arguments.callee);

       

                                    try

                                    {

                                              var myClass:Class = ApplicationDomain.currentDomain.getDefinition('MainClass') as Class;

                                    }

                                    catch(error:Error)

                                    {

                       //Alert.show("Error " + error, "Please Load TestLib Then Try Again!");

                       return;

                                    }

       

                                    var myInstance:Window = new myClass() as Window;

                          }


      This loads the SWF that is inside the SWC and then I can instantiate the class.

       

      Now the problem is when I use components not used in the main complication(For Ejmplor: In the main application does not use with CheckBok) entonceloading this SWF using that gives me an error component

       

      Error: Skin for LiningDamage104.WindowSkin105.contentGroup.HGroup121.BorderContainer122.BorderContainerSk in145.Group146.HGroup156.cbTherePreviousInspections cannot be found.

       

      The main application is sharing all libraries with RSL and forced to carry. TheLibrary Project where it came from the SWC is configured with all its librariesand external.

       

      I thought that just forces the loading of libraries in the main application would load all kinds of each and the others would have access to these classes, notthat the skin does not.

       

      I hope someone can help me. regards