C#程序与Flash的接口

来源:互联网 发布:jquery json解析{} 编辑:程序博客网 时间:2024/05/16 01:18

参照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#得出当前程序所在路径。
原创粉丝点击