internet explorer ie ExternalInterface bug fix div id tag

going from actionscript 2 a2 to as3 can be tough, and this forum will show the road to as3. as3 is not best suited for small animation or web projects, and is in someways a red headed stepchild of java and c++. But, it still has a purpose, for now.
Post Reply
darknkreepy3#
Site Admin
Posts: 247
Joined: Tue Oct 27, 2009 9:33 pm

internet explorer ie ExternalInterface bug fix div id tag

Post by darknkreepy3# »

When using an object and embed code to dynamically place flash .swf files in html with Javascript, you will find that even in 2010, ie is quirky compared to other browsers with the javascript 'ExternalInterface' call. If you create a string in JS and put it in a DIV, you should uniquely ID the object with ID="*****" whatever you wish (or need).

<object id="flashEx1" blah blah blah....

this will allow ie to have flash access the object since it was created after the initial page was rendered in it's DOM (document object model). Strangely where ie is so lax and helpful to beginner scripting programmers, in this case, it is very needy where Firefox, Safari, and Chrome are not.

I created a div where I kept replacing the innerHTML when I needed different aspects of a program I was writing to load a new interface in flash, and keep the session data accessible from the facebook api. So, I just embeded and tested in an html page, and used ExternalInterface to call changes when one flash process was done and another should be loaded. It didn't work in ie, and i got an error, so I looked around and found it was something unique to ie and this was the fix, an object 'id' tag with anything unique to the rest of the DOM.

example html and dynamic flash embedding function I created to ease the process

Code: Select all

<html>
	<head>
		<link type="text/css" rel="stylesheet" href="page.css" />
	</head>
	<body>
		<div class="wrap">
			<div id="mainArea">flash to go here</div>
		</div>

	</body>
</html>

<script language="javascript" type="text/javascript">
var to_root="";
var mainArea=document.getElementById('mainArea');
//-----
function show_flash(sFile,sW,sH)
	{
	var swf=to_root+sFile+".swf";
	var swfStr="<object id='flashSwf' classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0' width='"+sW+"' height='"+sH+"' align='middle'><param name='wmode' value='opaque' /><param name='allowScriptAccess' value='sameDomain' /><param name='allowFullScreen' value='false' /><param name='movie' value='"+swf+"' /><param name='quality' value='high' /><param name='wmode' value='opaque' /><param name='bgcolor' value='#ffffff' /><embed src='"+swf+"' quality='high' wmode='transparent' bgcolor='#ffffff' width='"+sW+"' height='"+sH+"' align='middle' allowScriptAccess='sameDomain' allowFullScreen='false' type='application/x-shockwave-flash' pluginspage='http://www.adobe.com/go/getflashplayer' /></object>";	
	return swfStr;
	}
//-----when a head is saved, flash calls this and a new swf to choose a body is loaded
function choose_snowman()
	{
	mainArea.innerHTML=show_flash("chooseSnowman","700","500");
	}
//-----
function swf_chooseImg()
	{
	mainArea.innerHTML=show_flash("chooseImg","700","500");
	}
//-----
window.onload=function()
	{
	swf_chooseImg();
	}
</script>
Post Reply