player.addEventListener('onStateChange', 'onytplayerStateChange') and IE

So, this is definatly one of the worst times i ever had with javascript and the blatent incompitancy of IE, below is my code, i realise that IE does not know of “addEventListener” although support was surpossed to be added in IE9 which still does not work, i have tried every fix i can think of and done all the research i can do on something that should just work anyway.


		google.load("swfobject", "2.1");
		var fired = 0;
		$(document).ready(function(){
			track(getQueryString()["vid"]);
		});
		function getQueryString() {
			var result = {},
				queryString = location.search.substring(1),
				re = /([^&=]+)=([^&]*)/g,
				m;

			while (m = re.exec(queryString)) {
				result[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
			}
			return result;
		}

		function track (vid) {
			var params = {
				allowScriptAccess: "always"
			};
			var atts = {
				id: "player"
			};
			var urlString = "http://www.youtube.com/v/" + vid + "&enablejsapi=1&playerapiid=ytplayer";
			swfobject.embedSWF(urlString, "embed", "640", "390", "10", "8", null, null, params, atts);
		}
			
		function onYouTubePlayerReady(playerId){
			var player = document.getElementById("embed");
			player.addEventListener('onStateChange', 'onytplayerStateChange');
		}
		
		function onytplayerStateChange(newState){
			if(newState != -1 && newState != 5 && !fired){
				fired = 1;
				var trackingPixel = new Image();
				trackingPixel.src = getQueryString()["unloadUrl"];
			}
		}



The function “onYouTubePlayerReady” does not get fired by IE for some(no) reason.

There are many threads on this issue but none seem resolved.

See it in action here: http://www.the7thchamber.com/swarm-embed/?unloadUrl=http://www.placeholder.com&vid=jGUADHvbiC8

Thanks for any help, this has been a very trying time for me, sometimes i love javascript but IE forces me to hate it, nothing like spending 30mins coding something then 4 hours making it work in IE.

Cheers,
Nick

I don’t know about IE9, but for IE it uses attachEvent()
http://www.quirksmode.org/js/events_advanced.html

But you are using jQuery in your example, so why not use .bind()?
http://api.jquery.com/bind/

Tried both, i believe addEventListener(‘onStateChange’, ‘onytplayerStateChange’); to be part of the google SWF api in some way because it shouldn’t work in FF without a 3rd parameter yet it does, so i think they have patched that function to work in all browsers (or at least tried).

I have tried embedding the player with a jQuery SWF plugin but found you need to embed it with the google SWF to fire events of the video, or at least, thats what i have deducted from it(http://jquery.thewikies.com/swfobject/).

Also using the IE developer toolbar, i have ensured i have it set to the normal IE9 mode, quirks is just pure fail on any page. I think the best place to start would be to find out why onYouTubePlayerReady is not firing but i google it and ive already read through everything…

Thanks anyway :slight_smile:

Why don’t you first attend to the error indicated in IE’s console?

I had not realized there was an error, i just put it to version 2.2 from 2.1 SWF however, since the error is in the framework, there is nothing i can do about it but post a thread. Thanks anyway, if you could give me some advice? that would be great.

Changing it to load SWFobject 2.1 resolved the error, however it still does not work in IE.