I`m using SWFObject for flash player on my webpage. Player as usual has buttons like Play, Stop, Pause etc. I need to catch moment, when my user click on any button and i need to execute some JS-function in this time. Sorry for my english and thanks a lot in advance. P.S. I dont have sources of my swf file.
AFAIK, this is done via the getURL()
function. You need to define the following in the action script of the flash file:
this.onClick = function(){
getURL("javascript:yourFunctionName();");
};
This means you can't just take any flash file and make it call JS functions, it must be defined within the flash file itself.
If I am wrong, I'd love to hear how this can be done more generically without editing the flash itself.
Calling a javascript function from flash can also be achieved using ExternalInterface.
You can use the method onPress.
Example
[button_name].onPress = function(){
//right here the stuff you wanna do
}
Hmm...
At the risk of going out on a limb, I actually don't think there's any way, within the confines of cross-browser Javascript proper, to hook into specific Flash player activity like that. In fact I'd be very surprised indeed if there were -- although I'd love to hear otherwise from someone more knowledgeable than me. :)
Assuming that's true, other than by some combination of listening (in the Javascript running in the context of your page) for focus and click events raised by the ActiveX/plug-in object itself (which probably wouldn't be very specific or dependable -- I don't even think click events get raised ), I doubt you'd have much luck.
From what brief testing I've done so far:
window.onload = function()
{
document.onclick = function()
{
alert("Clicked the page!");
}
document.getElementById("mySWFObjectID").onfocus = function()
{
alert("Focused the player!");
}
document.getElementById("mySWFObjectID").onclick = function()
{
alert("Clicked the player!");
}
}
... the player doesn't seem to be bubbling click events up to the page; in IE, the focus event fires, but not in Firefox, and only once, when the control gains focus. So aside from writing, maybe, a browser plug-in of some kind, to get you some lower-level access than what's exposed at the Javascript level, you might be out of luck on this one.
But again, if there's anyone out there who knows otherwise...