Question

Is it possible to detect when a Flash embed object has loaded completely? Are there events that can be subscribed to that work in all browsers?

Was it helpful?

Solution

Not directly, but it's easy to do if you have control over the SWF via ExternalInterface. First, in the flashvars for the SWF pass a callback name:

loadedCallback=swfLoadedCallback

Additionally, be sure the SWF has scriptAccess set to sameDomain or all

Next, Define a callback function in your page:

function swfLoadedCallback()
{
   // Note... if these were a real application, you would want 
   //    to use a setTimeout here to avoid Flash choking while 
   //    waiting for a response.
   alert('SWF loaded.  Do something.');
}

Then, in your SWF, add code like this:

import flash.external.ExternalInterface;
import flash.utils.setTimeout;

var params:Object = root.loaderInfo.parameters;
if (params && params.loadedCallback)
{
   // Set timeout to avoid syncronous issues
   setTimeout(function():void {
      if (ExternalInterface.available)
         ExternalInterface.call(params.loadedCallback);
   }, 1);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top