Wednesday, February 23, 2011

Call Flash function from javascript

In order to call flash from javascript, we have to select the flash object from javascript first. I solved this problem for our public website and enabled the interaction between flash object and html by javascript.


"myFlash" is the id of our flash object and function "MapIndicator" is an internal function of "myFlash". In order to call function "MapIndicator", we can use something like
"window.document.myFlash" in IE.
However, this function doesn't work in firefox. In order to make it work in both browsers, we used a function as follows to get the flash object

function getFlashMovieObject(movieName) {
if (navigator.appName.indexOf("Microsoft Internet") == -1) {
if (document.embeds && document.embeds[movieName])
return document.embeds[movieName];
}
else
{
return document.getElementById(movieName);
}
}

Then we use this function to call our flash method:

function CallFlash(ind) {
var obj = getFlashMovieObject("myFlash");
obj.MapIndicator(ind);
}

This page has very good explanation of these different methods:

http://www.permadi.com/tutorial/flashGetObject/

No comments:

Post a Comment