Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to control SWF through Javascript?

Here's the situation:

Client wants a looping SWF file to pause for two seconds before it begins playing all over again (it's a nice build animation on a logo, but the logo doesn't stay on the screen for very long because the movie repeats so users can't see the logo for long. This is irrelevant, but good back story.)

They provided me with a SWF file, but not FLA. When I asked for the FLA I was told the hard drive that contained the FLA crashed and it cannot be retrieved. So, that is pretty much a dead-end.

Before I go and try to de-compile the SWF and all that fun stuff, I wanted to know if there was any way that this could be done with HTML and Javascript. That is:

  1. Have the SWF loop
  2. Pause the movie for two seconds before it restarts

What do you think?

like image 370
lewiguez Avatar asked Feb 25 '23 10:02

lewiguez


2 Answers

This isn't easily possible with javascript, but it is very easy if you load the swf into another swf. You then have access to the main timeline of the original swf and you'd be able to 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);
}
like image 103
Zevan Avatar answered Mar 02 '23 22:03

Zevan


You could simulate this entirely in javascript with swfObject. You would need to time how long the animation is, add two seconds, and make that the time before the script restarts. heres a working example with the homestarrunner intro:

<!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>

plug that in here: http://htmledit.squarefree.com/

like image 39
greggreg Avatar answered Mar 02 '23 22:03

greggreg