The @alalonde solution no longer works, as Adobe imposes additional restrictions on characters that can be used for Flash event listeners. You can no longer use [] or (), which makes previous solutions to this problem obsolete. These characters generate the following javascript error:
Identifierstarts right after the numeric literal
Here is my solution (using period characters):
var players = {};
function onYouTubePlayerReady (idPlayer) {
var ytPlayer = document.getElementById (idPlayer);
var idPlayerParams = 'yt' + Math.floor (Math.random()*100000);
players [idPlayerParams] = {
idPlayer: idPlayer,
onStateChanged: function (state) {
alert ('youtube player state changed to: ' + state + ', player id: ' + idPlayer);
},
onError: function (err) {
alert ('youtube player error: ' + err + ', player id: ' + idPlayer);
}
};
ytPlayer.addEventListener ('onStateChange', 'players.' + idPlayerParams + '.onStateChanged');
ytPlayer.addEventListener ('onError', 'players.' + idPlayerParams + '.onError');
}
source
share