C# flash想到调用函数解决办法(二)参数传递

如果该事件处理函数的 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( " <invoke "   +  
          
"  name=\ " loadAndPlayVideo\ "  returntype=\ " xml\ " >
           < arguments >< string > "  + fileDialog.FileName + 
           " </string></arguments></invoke> " ); 

在 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

转载于:https://www.cnblogs.com/fengzhifengyi/archive/2008/10/22/1316449.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值