开发者

SWF file stops after 2nd loop

I have a swf file which I created using Adobe Flash professional CS5.5, it's a basic animation of some birds with an audio, it is meant to reply every 5 seconds, but for some reason after it starts to play the second loop it stops mid way and restarts the video from the beginning. Can anyone help me fix this?

This is my actionscript:

stop();
setInterval(wait, 10000);
function wait(){
    gotoAndPlay(1);
}

This is my javascipt to embed the movie on an html page:

<script type="text/javascript" src="/js/swfobject.js"></script>
<script type="text/javascript">
    var flashvars = {};
    var params = {};
    params.wmode = "transparent";
    var attributes = {};
    swfobject.embedSWF("/js/birdmovie.swf", "myAlternative", "290", "163", "9.0.0", "/js/expressInstall.swf", flashvars, param开发者_开发问答s, attributes);
</script>


Don't use setInterval because it's going to repeat indefinitely, especially if you keep creating interval at the end of your loop. Use setTimeout instead:

stop();
setTimeout(wait, 5000);
function wait(){
    gotoAndPlay(1);
}


so it gets to the end, stops, waits 10 seconds and then goes back to the beginning, but while it's playing, it's still counting another 10 seconds, in which it will loop.

So basically use

setTimeout(wait, 10000);

rather than

setInterval(wait, 10000);


I would recommend to name your setInterval and make sure you clear it first before starting it, otherwise you might get some unwanted confusing loops there.

stop();
clearInterval(my_interval);
my_interval = setInterval(wait, 10000);
function wait(){
    gotoAndPlay(1);
}

That way it will always clear any previous interval when it goes to first frame again, avoiding multiple intervals.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜