软件工程

本类阅读TOP10

·PHP4 + MYSQL + APACHE 在 WIN 系统下的安装、配置
·Linux 入门常用命令(1)
·Linux 入门常用命令(2)
·使用 DCPROMO/FORCEREMOVAL 命令强制将 Active Directory 域控制器降级
·DirectShow学习(八): CBaseRender类及相应Pin类的源代码分析
·基于ICE方式SIP信令穿透Symmetric NAT技术研究
·Windows 2003网络负载均衡的实现
·一网打尽Win十四种系统故障解决方法
·数百种 Windows 软件的免费替代品列表
·收藏---行百里半九十

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
C#程序与Flash的接口

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

参照sourceforge的开源项目,数据传输采用WDDX方法把对象及其属性串行化,接收端则解串行化解析出相应的数据。

 

//****************************************************************************
//                       ______
//                    .-"      "-.
//                   /    AOL     \
//                  |              |
//                  |,  .-.  .-.  ,|
//                  | )(__/  \__)( |
//                  |/     /\     \|
//        (@_       (_     ^^     _)
//   _     ) \_______\__|IIIIII|__/__________________________
//  (_)@8@8{}<________|-\IIIIII/-|___________________________>
//         )_/        \          /
//        (@           `--------`     AOL FLASH STUDIO.
//****************************************************************************
// @FileName SharpFlash.as
// @Package sharpflash
// @Description C#程序与flash交互的接口,采用Singleton模式,只允许一个接口
// @Author aol
// @Email [email protected]
// @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#得出当前程序所在路径。




相关文章

相关软件