Skip to content Skip to sidebar Skip to footer

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

Solution 1:

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);
}

Solution 2:

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/


Solution 3:

Try this http://www.permadi.com/tutorial/flashjscommand/


Post a Comment for "Possible To Control Swf Through Javascript?"