C#程式與Flash的介面

來源:互聯網
上載者:User

參照sourceforge的開源項目,資料轉送採用WDDX方法把對象及其屬性序列化,接收端則解序列化解析出相應的資料。

 

//****************************************************************************//                       ______//                    .-"      "-.//                   /    AOL     ///                  |              |//                  |,  .-.  .-.  ,|//                  | )(__/  /__)( |//                  |/     //     /|//        (@_       (_     ^^     _)//   _     ) /_______/__|IIIIII|__/__________________________//  (_)@8@8{}<________|-/IIIIII/-|___________________________>//         )_/        /          ///        (@           `--------`     AOL FLASH STUDIO.//****************************************************************************// @FileName SharpFlash.as// @Package sharpflash// @Description C#程式與flash互動的介面,採用Singleton模式,只允許一個介面// @Author aol// @Email jeremy1982@21cn.com// @Create 2004.10.10// @LastChange 2004.10.11// @History//****************************************************************************class sharpflash.SharpFlash{        private static var _instance:SharpFlash;                public static function get instance():SharpFlash        {                //trace(_instance);                if (_instance == null)                {                        _instance = new SharpFlash();                }                return _instance;        }                ///////////////////////////////////////////////////////                private var _data:String;                private var watch:Function;                private var wddx:Wddx;        private var callBackList:Array;                        //建構函式        private function SharpFlash()        {                wddx = new Wddx();                this.watch("data",onData);        }                //屬性data,由C#來賦值,flash監視其值的變化        public function get data():String        {                return _data;        }                public function set data(value:String):Void        {                _data = value;        }                //data變化處理方法        function onData(prop:String, oldVal:String, newVal:String)        {                // _root.result.text = newVal;                var xml:XML = new XML();                xml.parseXML(newVal);                                var response_xml:XMLNode = xml.firstChild.firstChild;                                //回呼函數ID                var tmp:XMLNode = response_xml.childNodes[0].firstChild;                                // callback 函數在這個結點裡面有一個或者兩個參數                // 通過解析從C#端發送的包的arg結點可以得出參數的數目                var argCount:Number = response_xml.childNodes[1].childNodes.length;                // _root.result.text = argCount;                switch (argCount)                {                        case 1:                        var arg1_wddx_xml:XML = new XML();                        arg1_wddx_xml.parseXML(response_xml.childNodes[1].childNodes[0].firstChild);                        var funcArgs = new Array(1);                        funcArgs[0] = wddx.deserialize(arg1_wddx_xml);                                                // 執行                        callBackList[tmp].callback.apply(callBackList[tmp].scope, funcArgs);                                                // debug 代碼:                        // _root.result.text = "1 Arg Result: [0] = " + funcArgs[0];                        break;                                                case 2:                        var arg1_wddx_xml:XML = new XML();                        arg1_wddx_xml.parseXML(response_xml.childNodes[1].childNodes[0].firstChild);                        var arg2_wddx_xml:XML = new XML();                        arg2_wddx_xml.parseXML(response_xml.childNodes[1].childNodes[1].firstChild);                        var funcArgs:Array = new Array(2);                        funcArgs[0] = wddx.deserialize(arg1_wddx_xml);                        funcArgs[1] = wddx.deserialize(arg2_wddx_xml);                                                // 執行                        callBackList[tmp].callback.apply(callBackList[tmp].scope, funcArgs);                                                // debug 代碼:                        //_root.result.text = "2 Arg Result: [0] = " + funcArgs[0] + "/n[1] = " + funcArgs[1];                        break;                        default:                        break;                }        }};
 
一個小樣本,由C#得出當前程式所在路徑。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.