简体   繁体   English

C#和Flash通信

[英]C# and Flash communication

有没有办法让C#获取swf通过ExternaInterface公开的方法列表?

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 the Shockwave ActiveX control itself; 刚刚意识到我误读了你的问题,因为你正在寻找通过Flex ExternalInterface class而不是Shockwave ActiveX control本身定义的方法; I'm gonna keep my original answer below as it might still be helpful regarding SWF usage via C# in general. 我将在下面保留我的原始答案,因为它可能仍然有助于通过C#一般使用SWF

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. 关于ExternalInterface我现在没有答案,但您可以查看Fun with C#和Flash Player 8 External API ,以了解如何通过C#首先使用此API。 (Another helpful sample might be Use External Interface of Flash 8 in Python and C# Applications .) (另一个有用的示例可能是在Python和C#应用程序中使用Flash 8的外部接口 。)

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 ;) 从我在前一篇文章中读到的内容来看,可能没有直接的解决方案,通过将精心设计的XML片段传递给CallFunction()的调用约定有点古怪,但你原则上应该能够将Georges 解决方案转化为此(就像我一样)说,它可能不会很漂亮;)

Good luck! 祝好运!


How to access a SWF from .NET via COM Interoperability: 如何通过COM互操作性从.NET访问SWF:

SWF for Windows is implemented by means of the Adobe Flash Player ActiveX control , consequently you would use it from .NET via COM Interoperability . SWF for Windows是通过Adobe Flash Player ActiveX控件实现的 ,因此您可以通过COM互操作性从.NET中使用它。

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. 您可以在Adobes网站上找到关于此的(遗留)文章/示例,请参阅在C#应用程序中嵌入Macromedia Flash Player以显示库存信息以获取概述(请注意有关示例代码不可用的文章的介绍性说明),但见下文。

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 . 更具体地说,您可以在本文的另一页上找到实现目标所需的初始步骤,请参阅在C#Windows应用程序中嵌入和与Macromedia Flash Player通信 - 特别是请按照文章/步骤进行操作在Visual Studio .NET中提供Macromedia Flash Player ActiveX控件

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 (named ShockwaveFlashObjects in Visual Studio 2008), which will open the Visual Studio object browser highlighting the assembly Interop.ShockwaveFlashObjects ; 完成概述步骤以将Shockwave ActiveX control添加到工具箱和特定项目引用后,您只需双击此引用(在Visual Studio 2008中名为ShockwaveFlashObjects ),这将打开Visual Studio对象浏览器,突出显示assembly Interop.ShockwaveFlashObjects ; then navigate down into the namespace ShockwaveFlashObjects , where you'll find, amongst others, the interface IShockwaveFlash , exposing (depending on your view filter) all its members, including the desired external methods with their respective C# signatures . 然后向下导航到namespace ShockwaveFlashObjects ,您可以在其中找到interface IShockwaveFlash ,公开(取决于您的视图过滤器)其所有成员,包括所需的外部方法及其各自的C#签名

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. 如果你可以访问你的swf(有源代码),那么你需要做的就是向一个函数添加一个回调函数,该函数返回你设置的所有方法,以便将ExternalInterface用作数组,字符串等。

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. 如果您无法访问swf源,可以创建另一个swf,使用ExternalInterface进行设置,以便可以调用它。 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 . 将原件SWF在您的新的,并在INIT处理程序,启动scavanging对于可能被称为连接使用,以ExternalInterface.addCallback方法的describeType

This is what I have in mind: 这就是我的想法:

var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.INIT, loaded);
    loader.load(new URLRequest('externalInterfaceTest.swf'));
function loaded(e:Event):void{
    //get all the methods in the loaded swf
    var methods:XMLList = describeType(e.target.content).method;
    for each(var method:XML in methods){
        //get methods defined by the author/not belonging to flash.display.*,flash.events.*,etc
        if(method.@declaredBy.indexOf('flash') == -1){
            trace('\nmethod description start========================');
            trace('methodName: ' + method.@name);
            trace('returnType: ' + method.@returnType);
            for each(var param:XML in method.parameter){
                trace('parameter ' + param.@index + ' type: ' + param.@type + ' optional: ' + param.@optional);
            }
            trace('\nmethod description end\n========================');
        }
    }
}

This would work if: 这将适用于:

  • the swf you load doesn't have a DocumentClass, the functions that might be added as callbacks are in the timeline, therefore public 您加载的swf没有DocumentClass,可能作为回调添加的函数在时间轴中,因此公开
  • the swf you load has all methods linked with ExternalInterface.addCallback declared public 您加载的swf具有与ExternalInterface.addCallback链接的所有方法声明为public

If you have no access to the swf or the developer, some ethical decompiling might help. 如果您无法访问swf或开发人员,则某些道德反编译可能会有所帮助。

A different approach would be to use classes developed by other developer to inspect swfs. 另一种方法是使用其他开发人员开发的类来检查swfs。 Here are some examples: 这里有些例子:

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 . 您可以在此处找到SWF文件规范。

Hope this helps. 希望这可以帮助。

You'll have to do this by reading the SWF file from C# code - not by communicating with it in any real sense. 您必须通过从C#代码中读取SWF文件来实现此目的 - 而不是通过与任何真正意义上的通信进行通信。 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 .) (您需要反编译字节码并查看哪些函数传递给ExternalInterface.addCallback 。)

The ActionScript bytecode format is documented , as is the SWF format . ActionScript的字节码格式文件 ,因为是SWF格式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM