C#与Flash交互

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

C#与Flash交互

第一步C#添加组件

打开VS2005-工具-选择工具箱项-COM组件-选择Shockwave Flash Object-确定

添加好组件往场景上拖放,如果提示注册需求注册

c# 注册控件-在运行输入-回车(flash9f.ocx这个文件以系统中实际文件为准。)

regsvr32 c:\windows\system32\macromed\flash\flash9f.ocx

第二步将Flash组件拖入场景

将Flash组件拖入场景,设置加载的swf路径。设置组件id。

第三步AS代码片段

刚开始用FSCommand与网页VBSCRIPT做了一个通讯,以为这样就能与C#通讯了,结果错误了。

还得用ExternalInterface.addCallback,ExternalInterface.call的方法来与C#通讯。

程序代码

import flash.external.*;

//向C#发送数据

ExternalInterface.call ("test", "str", Math.random ());

//接受C#发来的数据

ExternalInterface.addCallback ("c2flash", null, c2flash);

function c2flash (s:String)

{

out_txt.text = s;

}

第四步C#代码片段

程序代码

private void Form1_Load(object sender, EventArgs e)

{

flash.Movie = "E:/c2flash.swf";

flash.FlashCall += new AxShockwaveFlashObjects._IShockwaveFlashEvents_FlashCallEventHandler(flash_FlashCall); }

void flash_FlashCall(object sender, AxShockwaveFlashObjects._IShockwaveFlashEvents_FlashCallEvent e)

{

string s = nodeXml(e.request.ToString())[0].ChildNodes[0].InnerText.ToString();

//接受Flash传来的值

this.textBox1.Text = s;

throw new Exception("The method or operation is not implemented.");

}

private void button1_Click(object sender, EventArgs e)

{

//向Flash发送数据

callFunction("c2flash",this.textBox1.Text);

}

private void callFunction(string funName,string arg)

{

//C#传给Flash的值

flash.CallFunction(""+arg+"");

}

private XmlNodeList nodeXml(string s)

{

XmlDocument doc = new XmlDocument();

doc.LoadXml(s);

XmlNodeList list = doc.GetElementsByTagName("arguments");

return list;

}

相关文档
最新文档