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;
}