Can Flash and Javascript exchange data?

I am working on a chat application that uses flash sockets. I don't want to encode the whole interface in flash, so I was hoping to just use flash to talk to socketserver and call js to change dom.

Can this be done?

+4
source share
2 answers

To call the 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 the 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 take the SWFObject handle in JavaScript and call the ActionScript method as follows:

 function makeActionScriptCall() { var flash = document.getElementById(movieName); flash.methodName(parametersIfAny); } 

For more information see

+9
source

Use an ExternalInterface object so that your ActionScript can call JavaScript functions and vice versa.

+5
source

Source: https://habr.com/ru/post/1338370/


All Articles