Externalinterface - call javascript from SWF

HI,

im trying to call javascript function from my actionscript code but not working;

as3:

if (ExternalInterface.available)
  {
  try
  {
    ExternalInterface.addCallback("changeDocumentTitle",null);
  } 
  catch(error:Error)

      

js (inside speed file using swfobject)

function changeDocumentTitle() 
    {
        alert('call from SWF');
    }

      

Does anyone know what could happen?

0


a source to share


2 answers


If you are trying to call a JS function from your Flex application, you want to use ExternalInterface.call (...), not ExternalInterface.addCallback (...). From the docs:

public static function call (functionName: String, ... arguments): *

Calls a function exposed by the Flash Player container passing zero or more arguments. If the function is not available, the call returns null; otherwise, it returns the value supplied by the function. Recursion is not allowed in Opera or Netscape browsers; in those browsers a recursive call causes a null response. (Recursion is supported in Internet Explorer and Firefox browsers.)

If the container is an HTML page, this method calls a JavaScript function in the script element.



http://livedocs.adobe.com/flex/3/langref/flash/external/ExternalInterface.html

addCallback () is used when you want to expose an ActionScript function from your Flash application to an HTML container so that it can be called with JavaScript.

+7


a source


On a local system, communication between SWF and Javascript tends to be hampered by security issues. You can reconfigure your flash memory to allow some of these messages through the "Settings Manager".

There may also be a problem with "allowcriptacces" not being installed where you insert the Flash object.



Another problem might be that flash is trying to call javascript before javascript is loaded. The init ordering item can be quite annoying.

0


a source







All Articles