将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;
///
<summary>
///
flash向c#发数据的时候执行的函数
/// </summary>
/// <param
name="sender"></param>
/// <param
name="e"></param>
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();
}
}
///
<summary>
///
向flash
传值
///
< /summary>
///
<param
name="funName"></param>
/// <param
name="arg"></param>
private void callFunction(string funName, string
arg)
{
//C#传给Flash的值
axShockwaveFlash1.CallFunction("<invoke name=\"" + funName + "\"
returntype=\"xml\"><arguments><string>" + arg +
"</string></arguments></invoke>");
}
//CallFunction:他是axShockwaveFlash1控件的函数用于调用flash的函数给flash传递参数。
///
<summary>
///
向flash传值
调用函数
///
</summary>
///
<param
name="sender"></param>
/// <param
name="e"></param>
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 =
"";
}
}
原文:http://www.cnblogs.com/yaoguohua/p/3751985.html