Can I manage SWF through Javascript?

Here's the situation:

The client wants the SWF file with the loop to pause for two seconds before it starts playing again and again (this is a good animation of the assembly on the logo, but the logo does not remain on the screen for a very long time because the movie is repeated, so users cannot see the logo. It doesn’t matter, but a good background.)

They provided me with a SWF file, but not a FLA. When I asked for the FLA, I was told that the hard drive containing the FLA had crashed and could not be recovered. So it's almost a dead end.

Before going and trying to decompile SWF and all these funny things, I would like to know if there is a way to do this using HTML and Javascript. I.e:

  • At the SWF loop
  • Pause movie for two seconds until restart

What do you think?

+4
source share
3 answers

This is not easy to do using JavaScript, but it is very easy if you load the SWF into another SWF. After that, you will have access to the main timeline of the original SWF, and you can control it. If you want to control a movie called targetMovie.swf, you can do something like this:

var loader:Loader = new Loader();
loader.load(new URLRequest("targetMovie.swf"));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
addChild(loader);

var logoMovie:MovieClip;
function onComplete(evt:Event):void{
    logoMovie = MovieClip(loader.content);
    // call pauseMovie at end of timeline
    logoMovie.addFrameScript(logoMovie.totalFrames-1, pauseMovie);
}
function pauseMovie():void{
    logoMovie.stop();
    // delay for two seconds;
    setTimeout(function(){
      logoMovie.play();   
        }, 2000);
}
+5
source

You can simulate this completely in javascript using swfObject. You will need time, how much time the animation, add two seconds and make sure that the time until the script restarts. heres is a working example with the homestarrunner initiative:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
        <script type="text/javascript" src="http://swfobject.googlecode.com/svn-history/r409/trunk/swfobject/swfobject.js"></script>

        <script type="text/javascript">
            $(document).ready(function(){
              startSwf()
            })

            var restartTime = 24500 //in milliseconds
            function stopSwf(){
              swfobject.removeSWF("swfLoop");
              startSwf();
            }

            function startSwf() {
              $("body").append("<div id='swfLoop'></div>");
              swfobject.createSWF({data:"http://homestarrunner.com/newintro.swf", width:400, height:300}, null, "swfLoop");
              setTimeout('stopSwf()', restartTime);
            }
        </script>
    </head>
    <body></body>
</html>

connect here: http://htmledit.squarefree.com/

+2
source

Source: https://habr.com/ru/post/1784751/


All Articles