HI,
im trying to call a javascript function from my actionscript code but its not working;
as3:
if (ExternalInterface.available)
{
try
{
ExternalInterface.addCallback("changeDocumentTitle",null);
}
catch(error:Error)
js (inside velocity file using swfobject)
function changeDocumentTitle()
{
alert('call from SWF');
}
anyone know what could be happenin?
If you are trying to invoke a JS function from within your Flex app, you want to use ExternalInterface.call(...) and not ExternalInterface.addCallback(...). From the docs:
http://livedocs.adobe.com/flex/3/langref/flash/external/ExternalInterface.html
addCallback() is used if you want to expose an ActionScript function from your Flash app to the HTML container so that it can be invoked via JavaScript.
On the local system, communication between the SWF and Javascript tends to be hampered by security issues. You can reconfigure your flash to allow some of these communications via the "settings manager".
It may also be an issue with "allowscriptacces" not being set where you embed the flash object.
Another problem may be that flash tries to call javascript before the javascript is loaded. The init order thing can be quite annoying.