码迷,mamicode.com
首页 > 其他好文 > 详细

WPF内嵌Flsh并交互

时间:2014-05-26 19:10:54      阅读:271      评论:0      收藏:0      [点我收藏+]

标签:c   tar   a   int   com   strong   

将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 = "";
            }
        }

WPF内嵌Flsh并交互,布布扣,bubuko.com

WPF内嵌Flsh并交互

标签:c   tar   a   int   com   strong   

原文地址:http://www.cnblogs.com/yaoguohua/p/3751985.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!