将flash嵌入WPF页面:
//添加加载flash的控件
// 创建 host 对象
System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost();
// 实例化 axShockwaveFlash1
axShockwaveFlash1 = new AxShockwaveFlashObjects.AxShockwaveFlash();
// 装载.axShockwaveFlash1
host.Child = axShockwaveFlash1;
// 将 host 对象嵌入FlashGrid
this.FlashGrid.Children.Add(host);
if (strPhysName == "head")
{
axShockwaveFlash1.ScaleMode = 2;
}
// 设置 .swf 文件相对路径
string swfPath = System.Environment.CurrentDirectory;
swfPath += strPhysName == "head" ? @"\flash\心率\XinLv.swf" : @"\flash\脑电\" + "NaoDian.swf";
axShockwaveFlash1.Movie = swfPath;
如果需要与flash交互则需要以下操作:
注册flash调用c#的函数
axShockwaveFlash1.FSCommand += GameFlash_FSCommand;
///
/// flash向c#发数据的时候执行的函数
///
///
///
void GameFlash_FSCommand(object sender, AxShockwaveFlashObjects._IShockwaveFlashEvents_FSCommandEvent e)//接收flash传出参数
{
if (e.command == "sendData")
{
CloseMessage();
string strValue = e.args.ToString();
InsertUserReport(strValue);
this.Close();
}
else if (e.command == "end")
{
CloseMessage();
this.Close();
}
}
///
/// 向flash 传值
///
///
///
private void callFunction(string funName, string arg)
{
//C#传给Flash的值
axShockwaveFlash1.CallFunction("
}
//CallFunction:他是axShockwaveFlash1控件的函数用于调用flash的函数给flash传递参数。
///
/// 向flash传值 调用函数
///
///
///
private void timer_Tick(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(strzhuyili) && !string.IsNullOrEmpty(strfangsudu))
{
string setFS = strfangsudu.TrimEnd('|').Split('|')[0];
string setZY = strzhuyili.TrimEnd('|').Split('|')[0];
callFunction("setFS", setFS);//"setFS"是flash那边的函数,setFS是给该函数传递的参数。
callFunction("setZY", setZY);//同上解释
strzhuyili = "";
strfangsudu = "";
}
}