I am working on a chatting app that makes use of flash sockets. I don't want to code the entire interface in flash, so I was hoping to just use flash to talk to the socketserver and call js to modify the dom.
can this be done?
To call a JavaScript function from Flash, use the ExternalInterface.call
function in ActionScript:
import flash.external.ExternalInterface;
// Call a JavaScript function
ExternalInterface.call("your_javascript_function");
// Get a return value from a JavaScript function
var x:int = ExternalInterface.call("get_x");
// Pass an argument to a JavaScript function
var retval:int = ExternalInterface.call("some_js_function", "the-argument");
To call an ActionScript function from JavaScript, first use the ExternalInterface.addCallback
function in ActionScript:
// "methodName" is the method to call in JavaScript
// instanceObject.realMethod is the method that will be triggered
var successful = ExternalInterface.addCallback("methodName",
instanceObject,
realMethod);
Then, get a handle on the SWFObject in JavaScript and call the ActionScript method as follows:
function makeActionScriptCall() {
var flash = document.getElementById(movieName);
flash.methodName(parametersIfAny);
}
For more information, see:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With