C#/动作与AxShockwaveFlash [英] C# / ActionScript with AxShockwaveFlash

查看:990
本文介绍了C#/动作与AxShockwaveFlash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的动作,我试图AS和C#​​之间的通信。每个教程/解释,我觉得似乎是完全一样的,但我根本无法得到它的工作。 callFunction 抛出一个COM异常(E_FAIL),当我尝试调用 ExternalInterface.call()从AS ,它似乎永远不会。

我已经得到了这个在JavaScript / HTML工作,但我的想法对C#;我怀疑我做错了什么/在我作为不允许的。我编译AS文件与Adobe的Flex 4.6和mxmlc的。

编辑:我想弄清楚,这code仅显示测试与AS因为它似乎调用C#函数不容易出错(处理不需要XML参数)。另外,我运行一个测试一个,而(真)ExternalInterface.call(someFct,世界,你好); 循环在我作为我的CPU使用情况调试过程基本上相同,与AS(〜0.3%)没有说明。因此,似乎在code不执行的。

下面是我的AS文件:

 包
{
    进口的flash.external.ExternalInterface;
    公共类测试
    {
        公共功能测试()
        {
            ExternalInterface.call(someFct,世界,你好);
        }
    }
}
 

和在C#中我有一个的WinForms控制AxShockwaveFlash:

 私人无效的Ini​​tializeComponent()
{
    System.ComponentModel.ComponentResourceManager资源=新System.ComponentModel.ComponentResourceManager(typeof运算(Form1中));
    this.axShockwaveFlash1 =新AxShockwaveFlashObjects.AxShockwaveFlash();
    ((System.ComponentModel.ISupportInitialize)(this.axShockwaveFlash1))BeginInit在()。
    this.SuspendLayout();
    //
    // axShockwaveFlash1
    //
    this.axShockwaveFlash1.Enabled = TRUE;
    this.axShockwaveFlash1.Location =新System.Drawing.Point(104,67);
    this.axShockwaveFlash1.Name =axShockwaveFlash1;
    this.axShockwaveFlash1.OcxState =((System.Windows.Forms.AxHost.State)(resources.GetObject(axShockwaveFlash1.OcxState)));
    this.axShockwaveFlash1.Size =新System.Drawing.Size(574,314);
    this.axShockwaveFlash1.TabIndex = 0;
    this.axShockwaveFlash1.FlashCall + =新AxShockwaveFlashObjects._IShockwaveFlashEvents_FlashCallEventHandler(this.recv);
    this.Click + =新System.EventHandler(this.Form1_Click);
// ...
    ((System.ComponentModel.ISupportInitialize)(this.axShockwaveFlash1))EndInit()。
     this.ResumeLayout(假);
}
 

初​​始化SWF对象并接收其呼叫:

 私人无效Form1_Click(对象发件人,EventArgs的)
{
    axShockwaveFlash1.LoadMovie(0,@mypath中\ test.swf);
}

//从不执行
公共无效的recv(对象发件人,_IShockwaveFlashEvents_FlashCallEvent E)
{
    字符串s = e.request;
}
 

解决方案

我发现的问题。

1)正如我怀疑,COM对象需要一些种类的图形初始化,以在所有的工作。让您的主类扩展雪碧解决这个问题。

2)你显然不能使用 ExternalInterface.call() ExternalInterface.setCallback()的主类的构造函数直接。创建一个新的类,在主类的构造函数的一个实例,使在其构造函数 ExternalInterface的呼叫或其它任何功能解决这个问题。

Test.as:

 包
{
    导入flash.display使用*。
    公共类测试扩展Sprite
    {
        公共功能测试()
        {
            超();
            VAR X:测试1 =新的Test1();
        }
    }
}
 

和Test1.as:

 包
{
    进口的flash.external.ExternalInterface;
    公共类test1
    {
        公共职能的Test1()
        {
            ExternalInterface.call(接收,世界,你好);
        }
    }
}
 

我也有的没有的想法,为什么有人会downvote我的问题...

I am new to ActionScript and am trying to communicate between AS and C#. Every tutorial/explanation I find seems to be exactly the same, but I simply cannot get it to work. callFunction throws a COM exception ("E_FAIL"), and when I try calling ExternalInterface.call() from the AS, it never seems to.

I've gotten this to work in JavaScript/HTML, but I'm out of ideas for C#; I suspect I'm doing something wrong/not allowed in my AS. I compile the AS file with Adobe Flex 4.6 and mxmlc.

Edit: Just to clarify, this code shows only the test with calling a C# function from AS since it seems less error-prone (no xml argument handling needed). Also, I've run a test with a while(true) ExternalInterface.call("someFct", "Hello world"); loop in my AS and my CPU usage for the debug process is basically the same as with no instructions in the AS (~0.3%). So it seems the code doesn't execute at all.

Here is my AS file:

package
{
    import flash.external.ExternalInterface;
    public class Test
    {     
        public function Test()
        {
            ExternalInterface.call("someFct", "Hello world");
        }
    }
}

And in C# I have an AxShockwaveFlash control in WinForms:

private void InitializeComponent()
{
    System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
    this.axShockwaveFlash1 = new AxShockwaveFlashObjects.AxShockwaveFlash();
    ((System.ComponentModel.ISupportInitialize)(this.axShockwaveFlash1)).BeginInit();
    this.SuspendLayout();
    // 
    // axShockwaveFlash1
    // 
    this.axShockwaveFlash1.Enabled = true;
    this.axShockwaveFlash1.Location = new System.Drawing.Point(104, 67);
    this.axShockwaveFlash1.Name = "axShockwaveFlash1";
    this.axShockwaveFlash1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axShockwaveFlash1.OcxState")));
    this.axShockwaveFlash1.Size = new System.Drawing.Size(574, 314);
    this.axShockwaveFlash1.TabIndex = 0;
    this.axShockwaveFlash1.FlashCall += new AxShockwaveFlashObjects._IShockwaveFlashEvents_FlashCallEventHandler(this.recv);
    this.Click += new System.EventHandler(this.Form1_Click);
//...
    ((System.ComponentModel.ISupportInitialize)(this.axShockwaveFlash1)).EndInit();
     this.ResumeLayout(false);
}

Initializing the SWF object and receiving its call:

private void Form1_Click(object sender, EventArgs e)
{
    axShockwaveFlash1.LoadMovie(0, @"mypath\test.swf");
}

//Never executes
public void recv(object sender, _IShockwaveFlashEvents_FlashCallEvent e)
{
    string s = e.request;
}

解决方案

I found the problems.

1) As I suspected, the COM object needs some kind of graphic initialization in order to work at all. Making your main class extend Sprite solves this.

2) You apparently can't use ExternalInterface.call() or ExternalInterface.setCallback() in the main class' constructor directly. Creating an instance of a new class in the main class' constructor and making the ExternalInterface call in its constructor or any other function solves this.

Test.as:

package
{
    import flash.display.*;
    public class Test extends Sprite
    {     
        public function Test()
        {
            super();
            var x : Test1 = new Test1();
        }
    }
}

And Test1.as:

package
{   
    import flash.external.ExternalInterface;
    public class Test1
    {
        public function Test1()
        {
            ExternalInterface.call("recv", "Hello world");
        }
    }
}

I also have no idea why someone would downvote my question...

这篇关于C#/动作与AxShockwaveFlash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆