ExternalInterface not working in IE after page refresh

I have a strange situation in IE where JS cannot call flash using ExternalInterface after I click update. I know the movie is loading, and the code that makes ExternalInterface.addCallback() seems to end without errors

Here is a brief description of the steps to play:

  • Open IE and download the movie for the first time, ExternalInterface callback methods are available for JavaScript.
  • If I remove the update, the callback methods are not available, and I get the error Object doesn't support this property or method .
  • If I clear my cache and refresh the page, they will be available again.
  • If I delete the update again without clearing my cache, they are not available.
  • If I close the browser and open again, they will be available again.

I have come across this situation before, and I am sure that the extra delay required to load and create the swf instance is what allows ExternalInterface to configure correctly. The way I worked on this before was to add a random number to the end of the SWF url so it would never be used in the cache, but this is not a real solution.

Does anyone know how to solve this?

change

I should also mention that after updating, “ExternalInterface.available” is “true”, but “ExternalInterface.objectId” is “null”.

I tried to randomize the value of the id object and insert the name and identifier of the div container and in each case ExternalInterface.objectId remains null .


Additional Information:

I don’t see how the way I insert the movie will matter, but I thought I would include the code to be sure. My movie is not affected by the “click to activate” problem, and I do not want to use SWFObject in this case, since the flash movie is a backup if there is no HTML5 sound.

 var docContainer = document.createElement('div'); docContainer.innerHTML = '<object ' + 'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ' + 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" ' + 'id="mp3player" ' + 'width="300" ' + 'height="500">' + '<param name="allowScriptAccess" value="always" />' + '<param name="movie" value="mp3player.swf" />' + '<param name="quality" value="high" />' + '<param name="bgcolor" value="#ffffff" />' + '<embed ' +'src="mp3player.swf" ' + 'quality="high" ' + 'bgcolor="#ffffff" ' + 'width="300" ' + 'height="500" ' + 'swLiveConnect="true" ' + 'name="mp3player" ' + 'id="mp3player" ' + 'allowScriptAccess="always" ' + 'type="application/x-shockwave-flash" ' + 'pluginspage="http://www.adobe.com/go/getflashplayer" />' + '</object>'; document.body.appendChild(docContainer); 
+4
source share
3 answers

If anyone is wondering WHY this is happening, at least for Internet Explorer it seems that the Flash player is loaded as an ActiveX control that is completely separate from the DOM and JavaScript modules. When .swf is cached, it seems that the ActiveX control can load and run it before Javascript is ready to receive events from it.

This means that when Flash tries to use ExternalInterface to add callbacks, it will fail because JavaScript and the DOM were not loaded.

I fixed the problem by waiting for the first ENTER_FRAME event and then registering my callbacks. Like this:

 protected function registerExternalCallbacks(event:Event):void { removeEventListener(Event.ENTER_FRAME, registerExternalCallbacks); if (ExternalInterface.available) { ExternalInterface.addCallback("flash_play", play); ExternalInterface.addCallback("flash_setVolume", setVolume); ExternalInterface.call("player_ready"); } } // and then when the .swf loads, register the function on the event: addEventListener(Event.ENTER_FRAME, registerExternalCallbacks); 

This will force the player to wait until the callbacks are securely added, and then call the javascript function called player_ready to indicate that it is ready for use.

+6
source

The problem is that the ExternalInterface class will stop working as soon as the swf file is saved in your browser.

To overcome this obstacle, you must modify your html file and your SWF files in the following ways: Note. This solution has been tested in IE7.

HTML file - Add parameters to your swf file to make it unique. Therefore, the browser will think that you need to download a new swf file every time the page loads.

For example, if you use the SWFObject library (which you do not need), you must make the following settings:

 var cachecontrol = Math.floor(Math.random()*99999); var flashvars = {}; var params = {}; var attributes = {id:"movie"}; swfobject.embedSWF("movie.swf?nocache"+cachecontrol, "flashcontent", "100%", "100%", "10.1.0", "expressInstall.swf", flashvars, params, attributes); 

Also, add the following meta tag to ensure that your html file is not cached:

SWF file - If you download the swf file from the swf master, you have to use the same logic: var cachecontrol: String = Math.floor (Math.random () * 9999) .toString (); loader.load (new URLRequest ("movie.swf? nocache =" + cachecontrol));

Here is the source of the solution: http://www.emanuelz.com.mx/blog/cache-control-tips-for-flash-120 Note. You no longer need to do what is described above.

+6
source

There are a bunch of IE errors with ExternalInterface (and flash in general, ime) in different versions. Most recommended fixes suggest using the SwfObject js library, which captures all the ones I know of. http://www.timelesssky.com/blog/internet-explorer-flash-8-externalinterface-bug

+2
source

All Articles