Copy link to clipboard
Copied
Hi,
I'm trying to call an Actionscript 3 function exposed using externalinterface.addcallback from C# using callfunction(). When I use the XML API, it returned </invalid>. I tried using some code I found for Externalinterfaceproxy class on Google but it also is unresponsive.
I've tried adding the .swf to Flash Player's global security settings, no change. Within Actionscript the functions are called successfully. Externalinterface.available is true. AllowScriptAccess is set to "always" for the C# axshockwaveflash control.
Any idea what's missing? Can anyone point to working example code of C# -> Actionscript 3 function calls? Is there any procedure for troubleshooting the externalinterface API?
Thanks,
Alex
Copy link to clipboard
Copied
Anybody?
Is there any well-documented method of calling Actionscript 3 functions from C#?
Copy link to clipboard
Copied
The last time that I had to do something like that, I needed to use VBScript on the html page to "go-between" the C# and Actionscript. You can use ExternalInterface to communicate with VBScript.
Copy link to clipboard
Copied
Thanks for the reply. This is for a desktop Windows application; I'm using an axShockwaveFlash control in a Windows Form so there's no HTML page in between.
Copy link to clipboard
Copied
Then I'm no help at all. I've never tried that.
Copy link to clipboard
Copied
Thanks anyway.
Copy link to clipboard
Copied
Update: it appears that the ExternalInterface function is actually being called (I set a return value and I can see it coming back) but the problem is that my call to gotoAndStop isn't happening:
MovieClip(root).gotoAndStop("approved");
This is strange because I'm using a gotoAndStop in the Document Class constructor and it appears to be working, it's just not working when the function is called from ExternalInterface. Has anyone seen something like this or am I imagining things?
Copy link to clipboard
Copied
package
{
import flash.display.MovieClip;
import flash.external.ExternalInterface;
import flash.events.*;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class MyRoot extends MovieClip
{
public function MyRoot()
{
ExternalInterface.addCallback("idle", idle);
ExternalInterface.addCallback("authorizing", authorizing);
ExternalInterface.addCallback("approved", approved);
ExternalInterface.addCallback("failed", failed);
ExternalInterface.addCallback("serving", serving);
serving("now");
// var myTimer:Timer = new Timer(8000, 8); // 8 second delay
// myTimer.addEventListener(TimerEvent.TIMER, runOnce);
// myTimer.start();
//
// //Only necessary for troubleshooting
// function runOnce(event:TimerEvent):void {
// myTimer.stop();
// approved("now");
// }
}
public function idle(val:String):String
{
// this.gotoAndPlay(1);
MovieClip(root).gotoAndStop("idle");
return "ok idling";
}
public function authorizing(val:String):String
{
//this.gotoAndPlay(19);
//MovieClip(root).gotoAndStop("authorizing");
MovieClip(root).gotoAndPlay("authorizing");
MovieClip(root).stage.invalidate();
return "ok authorizing";
}
public function approved(val:String):String
{
//this.gotoAndPlay(29);
MovieClip(root).gotoAndStop("approved");
return "ok approved";
}
public function failed(val:String):String
{
//this.gotoAndPlay(41);
MovieClip(root).gotoAndStop("failed");
return "ok failed";
}
public function serving(val:String):String
{
//this.gotoAndPlay(51);
MovieClip(root).gotoAndStop("serving");
return "ok serving";
}
}
Copy link to clipboard
Copied
Another issue: the call to stage.invalidate() causes HRESULT E_FAILED to occur when running inside C# but does not cause any problem when testing the .swf on its own. I tried adding that line to see if it would force the gotoAndPlay() to work.
Copy link to clipboard
Copied
Solved: adding play() before gotoAndStop() solved the problem.
Copy link to clipboard
Copied
hay man im also doing windows form game from swf files and i wondered how can i get what exactly the game request, how do i use callfunction, getvariable and setvariable in c#