Hey,
So I have a small Flash application that plays a sound when a new message is received in a chat-box. The flash player is on a page embeded with an iframe.

<iframe width="1" height="1" frameborder="0" name="alerter" src="/chatbox/flash/alert/sound.php" id="chat_alert"></iframe>

In the parent window, a variable called new_message is used to keep track of wether it is a new message or not

if ( new_last_message != last_message ) {
		last_message = new_last_message;
		new_message = true;
	}

Then code within the iFrame checks this, if it is a new message then it plays the sound

function run_sound() {
	getMovie('viewer').new_msg();
}

function getMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    } else {
        return document[movieName];
    }
}

function check_new() {
	if ( parent.new_message == true ) {
		if ( parent.first_load == true ) {
			parent.first_load = false;
			parent.new_message = false;
		} else {
			parent.new_message = false;
			run_sound();
		}
	}
	//alert('Running Subfunction');
	setTimeout('check_new()', 100);
}

It works fine in every browser except IE which gives me the error Object Doesn't support this property or method refferencing line 309 of the file ( getMovie('viewer').new_msg(); )
Why is it only doing this in IE, it works fine in Safari, Firefox and Chrome
The chatbox can be viewed at (You need to have signed in but the accounts are free)

Dani AI

Generated

was on the right track: the IE error usually comes from how IE exposes the Flash plugin in the DOM and from timing. Other browsers often let the page grab the embed/object and call ActionScript methods immediately, while IE can hand back an HTML wrapper or an ActiveX host that does not expose the ExternalInterface callbacks until the SWF has finished initializing. That makes a direct method call fail with "Object doesn't support this property or method" even though the same call works elsewhere.

Two practical, reliable patterns that avoid browser-sniffing:

  • Get the element by ID (or use a small helper like SWFObject's getObjectById) instead of relying on window[name] vs document[name]. Make sure the same id is present on the object/embed so the reference is consistent.
  • Wait until the SWF is ready before calling its JS-exposed methods. The most robust handshake is for the SWF to call a JS function (via ExternalInterface.call) when it initializes; alternatively, poll for the method's existence and retry a short time later rather than calling immediately.

Example polling helper (place inside the iframe page that contains the SWF):

function callSwfWhenReady(swfId, methodName) {
  var swf = document.getElementById(swfId) || window[swfId];
  if (swf && typeof swf[methodName] === 'function') {
    swf[methodName]();
    return;
  }
  setTimeout(function(){ callSwfWhenReady(swfId, methodName); }, 100);
}

Additional notes: ensure parent/iframe are same-origin (otherwise access is blocked), and prefer a small initialization handshake from the SWF when possible — that avoids race conditions in IE. Given Flash is deprecated, consider replacing the tiny sound player with an HTML5 Audio fallback when updating the chat in the long term.

Recommended Answers

All 2 Replies

Why is it only doing this in IE

This might help http://www.permadi.com/tutorial/flashGetObject/ although given the apparent age of that page it might now be a better strategy to start with getElementById() [instead of ending up with that].

AHHH brilliant XD
IOU one pint =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.