通过主影片来获得所有子影片的systemmanager,然后分别传递给各个子影片。子影片通过各自的systemmanager来调用别的影片。

 

 

子模块

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
        <![CDATA[
            import mx.managers.SystemManager;
            public function output(s:String):void{
                trace(s);
            }
            
            public function CallFriend():void{
                SampleChildren(_SystemManager.application).output("call...");
            }
            
            private var _SystemManager:SystemManager;
            
            public function register(ASystemManager:SystemManager):void{
                _SystemManager=ASystemManager;
            }
                
        ]]>
    </mx:Script>
</mx:Application>

主模块

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
    <mx:Script>
        <![CDATA[
            import mx.managers.SystemManager;
            
            var Children1,Children2:SystemManager;
            
            private function onClick(e:Event):void{
                SampleChildren(Children1.application).register(Children2);
                SampleChildren(Children2.application).register(Children1);
            }
            
            private function initNestedAppProps():void {
                Children1 = SystemManager(myLoader.content);
                trace(Children1.application);
            }
            private function initNestedAppProps2():void {
                Children2 = SystemManager(myLoader2.content);
                trace(Children2.application);
            }
            
            private function onC1(e:Event):void{
                SampleChildren(Children1.application).CallFriend();
            }  
            private function onC2(e:Event):void{
                SampleChildren(Children2.application).CallFriend();
            }              
            
        ]]>
    </mx:Script>
    <mx:Button label="ClickMe" click="onClick(event);"/>
    
    <mx:Button label="c1 call c2" click="onC1(event);"/>
    <mx:Button label="c2 call c1" click="onC2(event);"/>
    
    <mx:SWFLoader id="myLoader" width="300"
        source="SampleChildren.swf"
        creationComplete="initNestedAppProps();"/>
    <mx:SWFLoader id="myLoader2" width="300"
        source="SampleChildren.swf"
        creationComplete="initNestedAppProps2();"/>    
</mx:Application>