How to catch a click on a flash player?

I am using SWFObject for a flash player on my web page. The player, as usual, has buttons such as Play, Stop, Pause, etc. I need to catch the moment when my user clicks on any button, and I need to execute some JS function at this time. Sorry for my English and thanks in advance. Postscript I have no sources for my swf file.

+4
source share
4 answers

AFAIK, this is done using the getURL() function. In the action of the script file of the flash file, you need to determine the following:

 this.onClick = function(){ getURL("javascript:yourFunctionName();"); }; 

This means that you cannot just take any flash file and force it to call JS functions, it must be defined inside the flash file itself.

If I am mistaken, I would like to hear how it can be done more universally without editing the flash itself.

+4
source

A javascript function call from flash can also be reached using ExternalInterface .

+3
source

You can use the onPress method.

Example

[button_name] .onPress = function () {

// right here the material you want to do

}

+1
source

Hm ...

At the risk of reaching a limb, I really do not think that in any case, within the framework of the JavaScript browser itself, to connect to the specific activity of the Flash player. In fact, I would be very surprised if I were, although I would like to hear differently from someone more knowledgeable than me. :)

Assuming this is a different truth from some combination of listening (in Javascript running in the context of your page) for the focus and clicks caused by the ActiveX / plug-in object itself (which probably wouldn't be very specific or reliable - I don't even I think click events are coming up), I doubt you will have much luck.

What short testing I've done so far from:

 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 does not seem to trigger click events on the page; in IE, the focal event fires, but not in Firefox, and only once when the control receives focus. Therefore, in addition to writing, maybe some browser plug-in, to get access to a lower level than the one that is displayed at the Javascript level, you might not be lucky.

But then again, if there is someone who knows otherwise ...

+1
source

All Articles