9 Replies Latest reply: Mar 27, 2014 8:41 PM by Flex harUI RSS

    [Flex 3] One SWF, multiple Applications?

    motionman95 Community Member

      I'm dealing with what might be a unique situation - I need to package multuple Applications within one exported SWF, and switch between which Application is loaded based on flash vars from the page the application will be in. File Size isn't a problem. Every solution I've tried so far has had no dice.

       

       

       

      Here is what I've tried:

       

      1. Subclassing SystemManager (info/create/getDefinitionForName functions) to override what Application is loaded. This didn't work as info/create can't be overriden, and overriding getDefinitionForName and suppling the Application class I want doesn't work either (I get the 1037 getStyle error).
      2. Using a main Application that functions as a dummy holder, and it decides what applications are loaded into a subclassed SWFLoader that addChild()s an Application class instance I supply it with. This works, sort of, with the Application class I supply being loaded, but things like mx:Script and mx:Style aren't respected in the sub-loaded Application. Here is how my subclassed SWFLoader looks (built from cannablized code in the SWFLoader source):

       

      package

      {

                import flash.display.DisplayObject;

                import flash.display.DisplayObjectContainer;

                import flash.display.Loader;

       

                import mx.controls.SWFLoader;

                import mx.core.mx_internal;

       

                use namespace mx_internal;

       

                public class AppLoader extends SWFLoader

                {

                          public function AppLoader()

                          {

                                    super();

       

                                    this.percentWidth = this.percentHeight = 100;

                          }

       

                          public function loadAppClass(classObj:Object):DisplayObject {

                                    var child:DisplayObject;

       

                                    contentHolder = child = new classObj();

                                    addChild(child);

       

                                    try

                                    {

                                              if (tabChildren &&

                                                        contentHolder is Loader &&

                                                        Loader(contentHolder).content is DisplayObjectContainer)

                                              {

                                                        Loader(contentHolder).tabChildren = true;

                                                        DisplayObjectContainer(Loader(contentHolder).content).tabChildren = true;

                                              }

                                    }

                                    catch(e:Error){}

       

                                    invalidateSize();

                                    invalidateDisplayList();

       

                                    return child;

                          }

                }

      }

       

      If there are better way to do this that don't require me loading external file/modules, that would be excellent. Ideally I'd like to just be able to swap between Application classes.