美文网首页
C# WinForm 与Flash 交互操作

C# WinForm 与Flash 交互操作

作者: 北风知我意 | 来源:发表于2017-06-28 11:51 被阅读481次

C# WinForm 与Flash 交互操作

要在 WinForm 中使用 Flash,通常需要用到 Shockwave Flash Object 这个 COM 组件。

(http://www.codeproject.com/csharp/fscommand.asp)

(http://www.codeproject.com/useritems/FlashDBInteract.asp)

具体步骤如下:

首先添加对 COM 组件 Shockwave Flash Object 的引用,将该组件拖到窗体上之后,可以设置如下关键属性:

Movie: flash 的存放地址

EmbedMovie: 是否嵌入到程序的资源中。

接下来你可以设置**一些属性,使得 Flash 的窗口最大化,隐藏掉其宿主程序的 C# WinForm 窗体。

在 Flash 的 ActionScript 中,可以通过 FSCommand 函数与 hosting app 通信,该函数有两个参数,分别是:

command: 命令名称

parameters: 参数

例子:

on(press){

fscommand("Circule", "Green");

}

在 C# 中,处理 flash 对象的 FSCommand 事件即可。

如果该事件处理函数的 EventArgs 为 e, 则有如下对应关系:

e.command -> flash 中调用 FSCommand 时的 command 参数;

e.args -> flash 中调用 FSCommand 时的 arguments 参数。

在 C# 中往 Flash 传递数值用 SetVariable 方法:

axShockwaveFlash1.SetVariable("variablename", "valueasstring");

对应的,有一个 GetVariable 方法可以获得 flash 中的变量值。

FSCommand 的参数只能传递一个,所以其功能存在一定的局限性。在你需要传递多个参数的时候,则需要在调用方用字符串拼接各个参数值,然后在被调用方重新解开。这种办法使得复杂的传值显得很丑陋。

不过,除了 FSCommand 外,我们还有另一种办法和 flash 通信,就是使用 Flash Player 8 External API.

(http://www.codeproject.com/cs/media/flashexternalapi.asp)

使用 External API,可以实现 ActionScript 和 C# 的双向调用。其好处就在于每次调用时的参数和返回值都通过一个 xml 文档来传递,这样就比 FSCommand 功能完善了很多。当然在 C# 中,我们也需要声明一下外部函数实现的对应关系。

代码片段:

Flash ActionScript 中声明提供给 hosting application 调用的回调函数:

import flash.external.ExternalInterface;

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

C# 中调用 Flash 的情形:

flashPlayer.CallFunction("

" name=\"loadAndPlayVideo\" returntype=\"xml\">

" + fileDialog.FileName +

"");

在 ActionScript 中调用 C# 函数:

ExternalInterface.call("ResizePlayer",

videoPlayer.metadata.width, videoPlayer.metadata.height);

在 C# 中声明被 Flash 调用的函数:

flashPlayer.FlashCall +=

new _IShockwaveFlashEvents_FlashCallEventHandler(flashPlayer_FlashCall);

在此,我们可以看到 C# 和 Flash 进行通信还是相当方便的。

除此之外,我顺便搜索到**一些和 flash 有关的不错的文章:

Flash and .NET with FlashRemoting

http://www.codeproject.com/aspnet/FlashRemoting.asp

Multiple File Upload With Progress Bar Using Flash and ASP.NET

http://www.codeproject.com/aspnet/FlashUpload.asp

Flash GUI for your exe using minimalistic approach (C++)

http://www.codeproject.com/useritems/FlashGui.asp

相关文章

  • C# WinForm 与Flash 交互操作

    C# WinForm 与Flash 交互操作 要在 WinForm 中使用 Flash,通常需要用到 Shockw...

  • Winform

    C# WinForm实践开发教程 C# WinForm实践开发教程——第一章 Windows编程基础C# WinF...

  • 解决 C# Winform Button 按了Tab后 会出现黑

    C# Winform Button按钮问题 C# Winform的 Button,大部分会选择 flat 样式,但...

  • dataGridView的使用

    C# — WinForm DataGridView篇 最近用C#的winform开发了一个项目,从中积累了一些各个...

  • Lua与C#交互原理

    Lua与C#交互原理 C#与Lua的交互主要是由Lua官方的提供的LuaInterface.dll库实现的。(1)...

  • C# NotifyIcon的使用

    | C# NotifyIcon的使用 一、winform 中添加 timer 、contextMenuStri...

  • winform计算器---C#

    winform计算器---C# using System; using System.Windows.Forms;...

  • winform软件使用授权资料

    基于C# winform 开发的 windows桌面应用 (根据自己的需求选择) C#授权实现相关文档 设置...

  • WinForm跨线程UI操作常用控件类大全

    前言 在C#开发的WinForm窗体程序开发的时候,经常会使用多线程处理一些比较耗时之类的操作。不过会有一个问题:...

  • c# winform

    System.Timers.Timer类是一个线程类,使用该定时器控制主线程的控件时,直接调用控件会报错:无法跨线...

网友评论

      本文标题:C# WinForm 与Flash 交互操作

      本文链接:https://www.haomeiwen.com/subject/jchucxtx.html