flex与flash进行交互及其通讯方式

 

                        Flexflash交互程序

Flex端程序

源代码TestFlex_Flash.mxml

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*">

    <mx:Script>

    <![CDATA[

        import flash.profiler.showRedrawRegions;

        import mx.controls.Alert;

        import flash.utils.Timer;

        import flash.events.TimerEvent;

        

        public function testf():void{

           Alert.show("已经调用");

           trace("ljlo");

           

              var time:Timer=new Timer(1000,1);

              time.start();

      time.addEventListener(TimerEvent.TIMER_COMPLETE,invokeFlash);             

        }

       

        public function loadSwf():void{

           //传入此flex对象

            Object(swfgame.content).setApp(this);

//             Object(swfgame.content).toFlex();

           

        }

       

        public function invokeFlash(inovevent:TimerEvent):void{

             //调用flash组件实例类对象的方法(myC为在flash帧中定义)

            Object(swfgame.content).myC.innerFunction();

        }

       

        public function parentMethod():void{

            Alert.show("调用父方法......");;

        }

    ]]>

    </mx:Script>

    <mx:SWFLoader id="swfgame" source="test.swf" x="174" y="75" width="330" height="200" creationComplete="loadSwf()"/>

    <local:TestComponent  id="component">

      

    </local:TestComponent>

</mx:Application>

 

源代码TestComponent.mxml

<?xml version="1.0" encoding="utf-8"?>

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300" xmlns:local="*">

    <mx:Script>

    <![CDATA[

        import mx.controls.Alert;

        

            public function testf():void{

           Alert.show("class组件已经调用了....");

           trace("ljlo");

        }

    ]]>

    </mx:Script>

<!--   <mx:SWFLoader id="swfgame" source="test.swf" x="174" y="75" width="61" creationComplete="loadSwf()"/>-->

     <local:VisualView id="view" />

</mx:Canvas>

 

 

源代码VisualView.as

 

package

{

    import mx.core.IMXMLObject;

    import mx.controls.Alert;

 

    public class VisualView implements IMXMLObject

    {

      protected var view : Object;

      protected var id : String;     

      public function initialized( document : Object, id : String ) : void

      {

         this.view = document;

         this.id = id;

        

      }    

     

      public function VisualView()

      {

          

      }

     

      public function testView():void{

        Alert.show("调用无视图方法。");

      }

      

      Public function invokeFlashMethod():void{

          Object(View.parentApplication.swfgame.content).

myC.innerFunction();

}    

 

    }

}

 

 

Flash端程序

Flash帧里代码如下

import flash.utils.Timer;

import flash.events.TimerEvent;

 

var flexApp:Object;

function setApp(ap:Object):void {

         this.flexApp=ap;

//      myC.passFlex(flexApp);

        

         var time:Timer=new Timer(1000,1);

         time.start();

         time.addEventListener(TimerEvent.TIMER_COMPLETE,toFlex);

}

var myC:MyClass=new MyClass();

 

function toFlex(eve:TimerEvent){

         flexApp.component.testf();       //flash调用flex子组件方法

         flexApp.component.view.testView();   //flash调用flex非可视组件组件中方法

    flexApp.testf();                    //flash直接调用flex加载该游戏作用域内方法

    flexApp.component.parentApplication.parentMethod();   //flash调用flex父组件方法

         myC.passFlex(flexApp);

}

 

MyClass类源代码

package {

        

         public class MyClass {

                   public var myObj:Object=null;

                   public function MyClass() {

 

                   }

                   public function passFlex(obj:Object) {

                            //obj.testf();

                            myObj=obj;

                   }

                   public function innerFunction(){

                            //myObj.component.testf();

                            trace("i am from the flash inner class")

                   }

         }

}

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值