How to detect which swf was loaded

Asked

Viewed 144 times

3

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

Follow the code:

<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 using the parameter onload but it doesn’t seem to work on the Object tag

* Oh also I can not use the swfObject, project limitations.

  • The most practical would be to use swfObject. Another alternative would perhaps be from within the SWF to use the external interface and call a Javascript to warn the page your swf loaded. http://stackoverflow.com/questions/883680/externalinterface-calling-javascript-from-swf

  • Thanks Tony, I had thought about this tmb, but I thought there was another way, I researched here and probably there is no other way, thanks for the XD reply

  • Why not use the recommended mode, which is swfObject?

  • It is a limitation of the project, because it deals with a banner 'special' in which javascript interacts with swf, and not allowed the insertion of swfObject, tmb I think it’s boring this but do what right.... higher orders

  • You can use or are already using jQuery?

  • so brsofilo the project has the limitation of being able to use only pure javascript(a bag), but I’ll take the advice from Tony that is to warn javascript when swf is loaded using the Externalinterface, thanks for the answer

Show 1 more comment

1 answer

1


An alternative is to use the Externalinterface for communication between Javascript and Actionscript. With it it is possible to pass Javascript commands to Actionscript and vice versa.

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

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 inherited from Ecmascript, communication between them is effective and functional, I believe you can use them together.

I don’t know if there is any other alternative, but for pure Javascript, I believe this is the most reliable.

  • Thank you, I had done this only in a more gamp way, I was calling the javascript function in the swf time line, but its way is more correct, thanks for the answer

Browser other questions tagged

You are not signed in. Login or sign up in order to post.