C#程序与Flash的接口

王朝c#·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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

pre {font-family:"Courier New", Courier, Arial; font-size: 12px;}

.operator {color: #000000;}

.keyword {color: #993300;}

.identifier {color: #000087;}

.properties {color: #000087;}

.identifier2 {color : #000087;}

.linecomment, .blockcomment {color: #808080;}

.string {color: #0000FF;}

//****************************************************************************

// ______

// .-" "-.

// / 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#得出当前程序所在路径。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航