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 雁过无痕 阅读(487) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 
<2008年1月>
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789

导航

统计

常用链接

留言簿(7)

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜