Externalinterface not working in Firefox but working in IE for invisible swf

This post was migrated over from Muziboo DevBlog. Yes ... as unrealistic as it may sound, yesterday, I ran into an issue where something worked in Internet explorer but not in Firefox. I was trying to call an actionscript functions on a swf file from javascript. This is a fairly standard thing and is well documented on the web. I followed all the steps (registering a callback and embedding the swf using swfobject library) and it worked perfectly in IE. I could call my actionscript functions using javascript in IE but in firefox it would occasionally fail and I would see the following two messages in firebug uncaught exception: [Exception... "Failure" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://localhost:9001/javascripts/swfobject.js?1259133537 :: anonymous :: line 4" data: no] $('movieName').asFunc() undefined method where movieName is the id of the swf file and asFunc is the function defined in actionscript using ExternalInterface.addCallback. After a lot of googling, I ran into this thread which explained the basic problem. Since my swf file was hidden in the footer of the page, the callbacks worked after I had once scrolled down and seen the footer. Yes as crazy as it sounds, that was really the problem.  Firefox wants you to see the swf once before you make the function call.  To make sure that the 1x1 sized swf file was always visible no matter where you are in the page, I added the following css rule #movieName { position: fixed; top: 0; left: 0; } This rule makes sure that no matter how much you scroll up or scroll down, the swf file is always at the same place (in this case, just at the starting of the page, relative to the browser window). You can read more about fixed positioning here. I am sure there must be a better explanation/solution for this problem but I have tried my approach and it atleast works. If you find a better solution, please post as a comment and I will update the post.

blog comments powered by Disqus
Hana Mohan
Hana Mohan