C# 和 Flash 通信
C# 有没有办法获取 swf 通过 ExternaInterface 公开的方法列表?
Is there any way for C# to get a list of the methods the swf exposes through ExternaInterface?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更新:
刚刚意识到我误读了你的问题,因为你正在寻找通过 Flex
ExternalInterface 类
而不是Shockwave ActiveX 控件
本身的类;我将在下面保留我的原始答案,因为它对于一般通过 C# 使用SWF
可能仍然有帮助。关于
ExternalInterface
我现在没有答案,但您可以查看 享受 C# 和 Flash Player 8 外部 API 的乐趣,首先了解如何通过 C# 使用此 API。 示例可能是在 Python 和 C# 应用程序中使用 Flash 8 的外部接口。)(另一个有用的 阅读前一篇文章,可能没有直接的解决方案,并且通过传递精心设计的调用约定 XML 片段 到
CallFunction()
有点奇怪,但你仍然应该能够翻译 Georges 原则上的解决方案(正如我所说,它可能不会很漂亮;)祝你好运!
如何通过 COM 互操作性从 .NET 访问 SWF:
SWF< Windows 的 /code>
是通过 Adobe Flash Player ActiveX 控件,因此您可以通过 COM 互操作性。
您可以在 Adobe 网站上找到与此相关的(旧)文章/示例,请参阅 嵌入Macromedia Flash Player 在 C# 应用程序中显示股票信息 了解概述(请注意本文中有关示例代码不可用的介绍性说明),但请参阅下文。
更具体地说您可以在本文的另一页上找到实现目标所需的初始步骤,请参阅在 C# Windows 应用程序中嵌入 Macromedia Flash Player 并与之通信 - 特别是请按照文章/步骤进行操作,直至并包括制作 Macromedia Flash 部分Visual Studio .NET 中提供了播放器 ActiveX 控件。。
完成将
Shockwave ActiveX 控件
添加到工具箱和特定项目引用的概述步骤后,您只需双击该引用(在 Visual Studio 2008 中名为ShockwaveFlashObjects
) ),这将打开 Visual Studio 对象浏览器 突出显示程序集 Interop.ShockwaveFlashObjects
;然后向下导航到命名空间 ShockwaveFlashObjects
,您将在其中找到接口 IShockwaveFlash
,公开(取决于您的视图过滤器)其所有成员,包括所需的成员具有各自 C# 签名的外部方法。Update:
Just realized that I've misread your question as you are looking for methods defined via the Flex
ExternalInterface class
rather than those of theShockwave ActiveX control
itself; I'm gonna keep my original answer below as it might still be helpful regardingSWF
usage via C# in general.Concerning
ExternalInterface
I don't have an answer right now, but you might look into Fun with C# and the Flash Player 8 External API to get an idea on how to use this API via C# in the first place. (Another helpful sample might be Use External Interface of Flash 8 in Python and C# Applications.)From what I'm reading in the former article there is likely no straight forward solution and the calling conventions via passing crafted XML fragments to
CallFunction()
are somewhat quirky, still you should be able to translate Georges solution to this in principle (as I said, it's likely not gonna be pretty ;)Good luck!
How to access a SWF from .NET via COM Interoperability:
SWF
for Windows is implemented by means of the Adobe Flash Player ActiveX control, consequently you would use it from .NET via COM Interoperability.You can find a (legacy) article/sample regarding this on Adobes site, see Embedding Macromedia Flash Player in a C# Application to Display Stock Information for an overview (please note the introductory note of the article regarding unavailability of the sample code), but see below.
More specifically you can find the initial steps you need to take to achieve your goal on another page of this article, see Embedding and Communicating with the Macromedia Flash Player in C# Windows Applications - in particular please follow the article/steps up to and including section Making the Macromedia Flash Player ActiveX Control Available Within Visual Studio .NET.
Once you have completed the outlined steps to add the
Shockwave ActiveX control
to your toolbox and to a particular projects references you can simply double click this reference (namedShockwaveFlashObjects
in Visual Studio 2008), which will open the Visual Studio object browser highlighting theassembly Interop.ShockwaveFlashObjects
; then navigate down into thenamespace ShockwaveFlashObjects
, where you'll find, amongst others, theinterface IShockwaveFlash
, exposing (depending on your view filter) all its members, including the desired external methods with their respective C# signatures.如果您可以访问您的 swf(有其源代码),那么您需要做的就是向一个函数添加一个回调,该函数返回您设置的所有方法,以便以数组、字符串等形式与ExternalInterface 一起使用。
如果您这样做无法访问 swf 源,您可以制作另一个 swf,使用ExternalInterface 设置它,以便可以调用它。在新的 swf 和 INIT 处理程序,开始搜寻可能使用 描述类型。
这就是我的想法:
如果
DocumentClass,函数
可能会在回调中添加
时间线,因此公开
链接到
外部接口.addCallback
公开声明
如果您无法访问 swf 或开发人员,一些道德反编译可能会有所帮助。
另一种方法是使用其他开发人员开发的类来检查 swf。
以下是一些示例:
getDefinitionNames
这些类可能无法提供您需要的确切功能,但它是您需要的一个很好的起点,只有您会使用二进制数据(我现在不太擅长)。您可以在此处找到 SWF 文件规范。
希望这有帮助。
If you can access your swf ( have the source to it ) then all you need to do is add a callback to a function that returns all the methods you've setup for use with ExternalInterface as an Array, String, etc.
If you do not have access to the swf source, you could make another swf, set it up with ExternalInterface so you can call it. Load the original swf in your new one and in the INIT handler, start scavanging for methods that might be called linked to ExternalInterface.addCallback using describeType.
This is what I have in mind:
This would work if:
DocumentClass, the functions that
might be added as callbacks are in
the timeline, therefore public
linked with
ExternalInterface.addCallback
declared public
If you have no access to the swf or the developer, some ethical decompiling might help.
A different approach would be to use classes developed by other developer to inspect swfs.
Here are some examples:
getDefinitionNames
These classes may not offer the exact functionality you need, but it's a good starting point for what you need, only you'll be looking using binary data( which I'm not very good at right now). You can find the SWF file specifications here.
Hope this helps.
您必须通过从 C# 代码读取 SWF 文件来完成此操作,而不是通过与它进行任何真正意义上的通信。这篇文章将为您指明正确的方向,但可能还有很多工作要做。 (您需要反编译字节码并查看哪些函数被传递给
ExternalInterface.addCallback
。)ActionScript 字节码格式为 记录,SWF 格式。
You'll have to do this by reading the SWF file from C# code - not by communicating with it in any real sense. This post will point you in the right direction, but there'll probably be quite a bit of work to do. (You'll need to decompile the bytecode and see what functions get passed to
ExternalInterface.addCallback
.)The ActionScript bytecode format is documented, as is the SWF format.