Chris Sobolewski
Chris Sobolewski

Reputation: 12945

swfobject event listeners not working?

I have essentially taken the code from the youtube api tutorial, starting the video playback immediately, and invoking a callback for state changes. Playing is working, so I know the onYouTubePlayerReady function is firing, and the ytplayer object is defined. However, the event listener is not working.

Here is the callback function for when the youtube player is loaded:

function onYouTubePlayerReady(playerId) {
  ytplayer = document.getElementById("myytplayer");
  ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
  ytplayer.playVideo();
}

And here is the event listener:

function onytplayerStateChange(newState) {
 alert("Player's new state: " + newState);
}

I hate when no one answers and I google it later, only to find out my stack overflow question is one of the top results.

Upvotes: 0

Views: 650

Answers (2)

May
May

Reputation: 207

Check your "myytplayer" where did you define that . I had the same problem , it was due to the wrong reference of an Id . check that again.

Upvotes: 0

Hayden
Hayden

Reputation: 11

To quote the YT API reference:

Note: To test any of these calls, you must have your file running on a webserver, as the Flash player restricts calls between local files and the internet.

Upvotes: 1

Related Questions