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:
varloader:Loader = newLoader();
loader.load(newURLRequest("targetMovie.swf"));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
addChild(loader);
varlogoMovie:MovieClip;
functiononComplete(evt:Event):void{
logoMovie = MovieClip(loader.content);
// call pauseMovie at end of timeline
logoMovie.addFrameScript(logoMovie.totalFrames-1, pauseMovie);
}
functionpauseMovie():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><htmlxmlns="http://www.w3.org/1999/xhtml"lang="en"xml:lang="en"><head><metahttp-equiv="Content-Type"content="text/html; charset=iso-8859-1" /><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script><scripttype="text/javascript"src="http://swfobject.googlecode.com/svn-history/r409/trunk/swfobject/swfobject.js"></script><scripttype="text/javascript">
$(document).ready(function(){
startSwf()
})
var restartTime = 24500//in millisecondsfunctionstopSwf(){
swfobject.removeSWF("swfLoop");
startSwf();
}
functionstartSwf() {
$("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/
Post a Comment for "Possible To Control Swf Through Javascript?"