Module之間的通信交互解決辦法

          看看以下的代碼,有點意思
          1.子Swf的Code,SampleChildren.mxml

          <?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>

          2.主swf的Code, SampleParent.mxml
          <?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>

          注意到SampleParent.mxml文件中SampleChildren類的使用了么,原來mxml文件也是對應一個同名的actionscript class的,這個class是從Application派生的。但是要注意哦,SampleParent.mxml編譯時必須能夠看到SampleChildren類的Source。

          posted on 2008-01-04 12:27 雁過無痕 閱讀(505) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2008年1月>
          303112345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導航

          統計

          常用鏈接

          留言簿(7)

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 横峰县| 泰兴市| 仪陇县| 沂水县| 偏关县| 通州市| 仁化县| 扎兰屯市| 贡觉县| 阳城县| 闽侯县| 漳浦县| 恩施市| 阳信县| 民县| 永泰县| 盐城市| 石台县| 延庆县| 平谷区| 武隆县| 随州市| 文水县| 呈贡县| 富阳市| 施甸县| 青浦区| 陇川县| 葫芦岛市| 安岳县| 五寨县| 南雄市| 民丰县| 和顺县| 东平县| 沅江市| 犍为县| 白水县| 施甸县| 高陵县| 麻江县|