Here is the final code that will enable you to have a subapplication and send a 
simple event to the parent from the child...


PARENT APPLICATION...

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; layout="absolute" 
applicationComplete="init()" preinitialize="preinit()">


  <mx:Script>
    <![CDATA[
        import mx.controls.SWFLoader;
        import mx.managers.SystemManager;
                import mx.events.FlexEvent;
                import mx.managers.PopUpManager; 
                import mx.core.Application;
                import flash.events.Event;
                import mx.collections.ArrayCollection;
                
                [Bindable]
                private var testDP:ArrayCollection = new ArrayCollection();
                                
        private function preinit():void{
        }



                private function init():void{
                        
                        
loader.load("http://71.36.29.20:8888/SubAppTestChild.swf";);
                        loader.loadForCompatibility = true;
                        loader.trustContent = true;
                        loader.visible = true;

                        
systemManager.addEventListener(ResizeEvent.RESIZE_EVENT, newText);
                }


                private function newText(evt:ResizeEvent):void{
                        testDP.addItem(evt.someText);   
                }

        private function testChild(event:MouseEvent):void{
                        (loader.content as Object).application.loadDialog();
        }
        
        ]]>
    </mx:Script>

<mx:VBox width="100%" height="100%">
        <mx:Button click="testChild(event)" label="Open SubApplication"/>       
        <mx:Spacer height="20"/>
        <mx:List width="100%" height="100%" dataProvider="{testDP}"/>   
        <mx:SWFLoader visible="false" id="loader"/>
</mx:VBox>

</mx:Application>



CHILD/SUBAPPLICATION

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; layout="absolute" 
preinitialize="preinit()" viewSourceURL="srcview/index.html">
        
        <mx:Script>
                <![CDATA[
                        import mx.controls.Alert;

                        import mx.managers.PopUpManager;
                        

                        public function loadDialog():void{
                                var test:TestView = 
PopUpManager.createPopUp(systemManager.getSandboxRoot(), TestView, true) as 
TestView;
                PopUpManager.centerPopUp(test);                 
                        }       
                        
                        
                                                
                ]]>
        </mx:Script>
</mx:Application>


CHILD VIEW

<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow  xmlns:mx="http://www.adobe.com/2006/mxml"; width="500" 
height="500" title="TitleWindow in SubAppTestChild" showCloseButton="false" 
creationComplete="init()">
        
    <mx:Script>
        <![CDATA[
                import mx.events.CloseEvent;
                        import mx.managers.PopUpManager;
                        import ResizeEvent;
                        
                        private function init():void{
                        }               


                        private function close(evt:MouseEvent):void{
                                PopUpManager.removePopUp(this);
                        }
                        
                        private function sendParent(evt:MouseEvent):void{
                        
                                var testEvent:ResizeEvent = new 
ResizeEvent(ResizeEvent.RESIZE_EVENT, false, false, "Test To Parent");
                                
systemManager.getSandboxRoot().dispatchEvent(testEvent);        
                        }
                ]]>
        </mx:Script>


        <mx:VBox width="100%" height="100%" verticalAlign="middle" 
horizontalAlign="center">
        <mx:TextArea width="100%" height="100%" wordWrap="true" text="This 
popup is in SubAppTestChild and was built with the 3.2SDK.  The parent was 
written with the 3.4SDK.  For those interested, SWF files built with different 
SDK's cannot load one-another unless you make a few small tweaks to accomodate 
it.  Primarily the loadForCompatibility flag of SWFLoader.  The rules change a 
bit when using this flag and the child SWF needs to be tweaked to be able to 
communicate with the parent as it has been 'sandboxed'."/>
        <mx:HBox width="100%" horizontalAlign="right">
        <mx:Button click="sendParent(event)" label="Send 'Test To Parent' 
String to parent list box"/>
        <mx:Button label="Close" id="cancelButton" click="close(event)"/>
        </mx:HBox>
        </mx:VBox>
</mx:TitleWindow>




RESIZE EVENT

package
{
        import flash.events.Event;

        
        public class ResizeEvent extends Event
        {
                public static const RESIZE_EVENT:String = "RESIZE_EVENT";
        
                private var _someText:String;
                
                public function get someText():String{
                        return _someText;
                }

                public function ResizeEvent(type:String, bubbles:Boolean, 
cancelable:Boolean, someText:String)
                {
                        super(type, bubbles, cancelable);
                        
                        _someText = someText;
                }
                
        }
}






--- In flexcoders@yahoogroups.com, "jamesfin" <james.alan.finni...@...> wrote:
>
> Understood!  I'll add that to my blog.
> 
> Thanks again.
> 
> --- In flexcoders@yahoogroups.com, Alex Harui <aharui@> wrote:
> >
> > TopLevelSystemManager is might be used by a sub-app of that sub-app to get 
> > to its parent sub-app if they are both on the same version and not using 
> > loadForCompatibility (did you follow that?)
> > 
> > LoaderContext is available for those who really know what they are doing 
> > and need explicit control for some configuration we don't support with the 
> > Marshall Plan, usually for controlling the policy file parameter.  The 
> > marshall plan does not support re-using an appdom.  LoadForCompatibility 
> > refreshes the loaderContext before each load.
> > 
> > 
> > On 2/1/10 4:01 PM, "jamesfin" <james.alan.finnigan@> wrote:
> > 
> > 
> > 
> > 
> > 
> > 
> > And...
> > 
> > With what use-case would the loaderContext be used?
> > 
> > --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , 
> > "jamesfin" <james.alan.finnigan@> wrote:
> > >
> > > Thanks for the feedback.  Ironically, I had just found the 
> > > systemManager.getSandboxRoot() reference and was putting it in to test!
> > >
> > > While on the same subject, is systemManager.topLevelSystemManager used in 
> > > a non-sandboxed-sub-app?
> > >
> > > I'll blog this for sure as it was quite a hike around the mountain.
> > >
> > > Thx again!
> > >
> > > --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , 
> > > Alex Harui <aharui@> wrote:
> > > >
> > > > Couple of things:
> > > >
> > > >
> > > >  1.  You should not be setting a loaderContext.  It doesn't affect this 
> > > > test case, but it is not recommended practice.  Set 
> > > > loadForCompability=true BEFORE you call load().  I modified your init() 
> > > > function to look just like this:
> > > >
> > > >             private function init():void{
> > > >
> > > >                 loader.loadForCompatibility = true;
> > > >                 loader.load("SubAppTestChild.swf");
> > > >             }
> > > >
> > > > 2. I thought the original goal was to get the sub-apps popup to center 
> > > > in the main app, but the code looked like the goal was to center 
> > > > between two lines.  If the goal is to center in the main app, I 
> > > > adjusted the code to look like this:
> > > >
> > > >             public function loadDialog():void{
> > > >                 var test:TestView = 
> > > > PopUpManager.createPopUp(systemManager.getSandboxRoot(), TestView, 
> > > > true) as TestView;
> > > >                 PopUpManager.centerPopUp(test);
> > > >             }
> > > >
> > > >
> > > >
> > > > On 2/1/10 11:32 AM, "jamesfin" <james.alan.finnigan@> wrote:
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > I've been trying to center a dialog in a sub application but haven't 
> > > > had any success.  All SubApplication experts can pitch-in here...
> > > >
> > > > Backgrounder...SubApps are cool because two SWF's can be compiled with 
> > > > different SDK's and can still work together.
> > > >
> > > > The upper/left-hand corner of the dialog appears between the two 
> > > > HRule's because that is where the SWFLoader resides in the parent MXML. 
> > > >  The dialog isn't clipped in any way.
> > > >
> > > > I've tried many combinations to get the dialog to center but it won't 
> > > > budge.
> > > >
> > > > For a quick demo...
> > > >
> > > > http://71.36.29.20:8888/SubAppTestParent.html
> > > >
> > > > Parent Source...
> > > >
> > > > <?xml version="1.0" encoding="utf-8"?>
> > > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; 
> > > > layout="absolute" applicationComplete="init()" 
> > > > preinitialize="preinit()">
> > > >
> > > > <mx:Script>
> > > >  <![CDATA[
> > > >  import mx.controls.SWFLoader;
> > > >  import mx.managers.SystemManager;
> > > > import mx.events.FlexEvent;
> > > > import mx.managers.PopUpManager;
> > > >
> > > >  private function preinit():void{
> > > > // Security.allowDomain("*");
> > > >  }
> > > >
> > > > private function init():void{
> > > >
> > > > var context:LoaderContext = new LoaderContext();
> > > > context.securityDomain = SecurityDomain.currentDomain;
> > > > context.applicationDomain = new ApplicationDomain();
> > > > loader.loaderContext = context;
> > > > loader.load("http://71.36.29.20:8888/SubAppTestChild.swf";);
> > > > loader.loadForCompatibility = true;
> > > > loader.trustContent = true;
> > > > }
> > > >
> > > > private function testChild(event:MouseEvent):void{
> > > > (loader.content as Object).application.loadDialog();
> > > >  }
> > > >
> > > >  ]]>
> > > >  </mx:Script>
> > > >
> > > > <mx:VBox width="100%">
> > > > <mx:HBox width="100%">
> > > > <mx:Button click="testChild(event)" label="Open SubApplication"/>
> > > > <mx:Text text="The popup top/left corner should be between the two 
> > > > HRule lines"/>
> > > > </mx:HBox>
> > > > <mx:HRule width="100%"/>
> > > > <mx:SWFLoader id="loader"/>
> > > > <mx:HRule width="100%"/>
> > > > </mx:VBox>
> > > >
> > > > </mx:Application>
> > > >
> > > > Child Source...
> > > >
> > > > <?xml version="1.0" encoding="utf-8"?>
> > > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; 
> > > > layout="absolute" preinitialize="preinit()" 
> > > > viewSourceURL="srcview/index.html">
> > > >
> > > > <mx:Script>
> > > > <![CDATA[
> > > >
> > > > import mx.managers.PopUpManager;
> > > >
> > > > private function preinit():void{
> > > > // Security.allowDomain("*");
> > > >  }
> > > >
> > > > public function loadDialog():void{
> > > > var test:TestView = PopUpManager.createPopUp(Application.application as 
> > > > DisplayObject, TestView, true) as TestView;
> > > >      PopUpManager.centerPopUp(test);
> > > > }
> > > >
> > > > ]]>
> > > > </mx:Script>
> > > > </mx:Application>
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Alex Harui
> > > > Flex SDK Team
> > > > Adobe System, Inc.
> > > > http://blogs.adobe.com/aharui
> > > >
> > >
> > 
> > 
> > 
> > 
> > 
> > 
> > --
> > Alex Harui
> > Flex SDK Team
> > Adobe System, Inc.
> > http://blogs.adobe.com/aharui
> >
>


Reply via email to