How to detect that the swf was loaded

3

I wonder if it is possible to detect when swf is loaded:

Follow the code below:

<object id="teste"  name="teste" type="application/x-shockwave-flash" data="120x600.swf" width="550" height="400" onload="alert('carregado')">
   <param name="movie" value="120x600.swf"/>
   <param name="quality" value="high"/>
   <param name="allowscriptaccess" value="always"/>
   <a href="http://www.adobe.com/go/getflash">
   <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif"alt="Get Adobe Flash player"/>
   </a>
</object>

* I tried to use the parameter onload but it does not seem to work in the object tag

* I also can not use swfObject , project limitations.

    
asked by anonymous 01.09.2014 / 17:58

1 answer

1

An alternative is to use the ExternalInterface for communication between JavaScript and ActionScript. It is possible to pass commands from JavaScript to ActionScript and vice versa.

First you can listen to your SWF load using the code below in the first frame of the application:

this.loaderInfo.addEventListener(Event.OPEN, iniciouCarregamento);
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, carregando);
this.loaderInfo.addEventListener(Event.COMPLETE, carregouSWF);

function iniciouCarregamento(e:Event):void {
    trace("Iniciou carregamento");
}

function carregando(e:ProgressEvent):void {
    trace("Carregando..."+Number((e.bytesLoaded/e.bytesTotal)*100));
}

function carregouSWF(e:Event):void {
    trace("Carregou o SWF!");
    ExternalInterface.call("console.log", "Carregou o SWF!"); //Chama uma função do javascript, no caso, o "console.log", e passa como parâmetro a string "Carregou o SWF!"
}

In javascript you can use a custom function and call it by the same method like this:

Javascript:

function escutarSWF(param) {
     console.log(param);
}

ActionScript:

ExternalInterface.call("escutarSWF", "Olá! Eu sou o ActionScript!");

Because the two languages are inheritances of the ECMAScript , communication between them is effective and functional, I believe you can use them together.

I do not know if there is any other alternative, but for pure JavaScript, I think this is the most reliable.

    
02.09.2014 / 14:35