PDA

View Full Version : Find Flash Movie in Safari DOM?


bwilson
09-02-2009, 03:36 PM
I'm calling an ActionScript function in my flash movie from JavaScript...it's defined in ExternalInterface as a callback. This works fine in IE on Windows and in FireFox on Windows and Mac. Does not work in Safari or Opera on Mac, however.

Below is the Javascript that I'm using to invoke the ActionScript function; I got this from the Adobe documentation for ExternalInterface. Running this code in Safari or Opera, the "Can't find application" alert is displayed.

Anyone know what DOM object to look in for the instance of the Flash movie for Safari and Opera?

BTW, I'm using SWFObject 2 to manage the flash movie, both the id and name of the nested "object" tags are set to "flashContent"...

swfobject.registerObject("flashContent", "9.0.0");

function findFlashApp(appname) {
if ( navigator.appName.indexOf('Microsoft') != -1 ) {
// MSIE
return window[appname];
} else {
// FireFox - not Safari or Opera?
return document[appname];
}
}

function clickIpAddress(ipaddr) {
var app = findFlashApp('flashContent');
if ( app == null ) {
alert("clickIpAddress(): can't find application");
return;
}

if ( app.submitIpAddress != null ) {
app.submitIpAddress(ipaddr);
} else {
alert("clickIpAddress(): can't find interface function submitIpAddress()");
}
}

jasonJ
09-02-2009, 05:05 PM
Can't you simply write:

var app = document.getElementById('flashContent');

instead of

var app = findFlashApp('flashContent');

?
You just want to get to the element with the 'flashContent' id, right?

tadster
09-03-2009, 08:02 AM
this works for me (at least on Safari Win):


function callascallback(flashid)
{

try
{
var flashcontent=window.document.getElementById(flashi d);
}
catch(e)
{
try
{
var flashcontent=window.document.flashid;
}
catch(e)
{
var movie=flashid;

if (navigator.appName.indexOf("Microsoft")!=-1 || navigator.appName.indexOf("MSIE")!=-1)
{
if (window.document[movie])
{var flashcontent=window.document[movie];}
else
{var flashcontent=window[movie];};
}else{
if (document.embeds[movie])
{var flashcontent=document.embeds[movie];}
else
{var flashcontent=document[movie];};
}
}
}
try
{
//the actual call to the callback function
flashcontent.jsfunction();
}
catch(e)
{
//this catch is for if all failed
var cantcommunicate="yes";
}
}