4

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.

4 Answers 4

4

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.

Sign up to request clarification or add additional context in comments.

Comments

3

Calling a javascript function from flash can also be achieved using ExternalInterface.

2 Comments

One moment here: i dont have sources of my flash web player.
Definitely right, though -- ExternalInterface is the way to go when you have access to the source. It's a beautiful thing. :)
1

You can use the method onPress.

Example

[button_name].onPress = function(){

//right here the stuff you wanna do

}

Comments

1

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...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.