为什么 SetInterval 不起作用(它只工作一次)

Why SetInterval doesn't work (it works only once)

本文关键字:一次 工作 SetInterval 不起作用 为什么      更新时间:2023-09-26

我为.swf做了一个进度条。

<head>代码:

function ProgressBar(){
setTimeout(function (){
if (swfobject.getObjectById("Object").IsPlaying()) {
var TotalFrames = swfobject.getObjectById("Object").TotalFrames();
console.log(console.log("TotalFrames: " + TotalFrames));
var TCurrentFrame = swfobject.getObjectById("Object").CurrentFrame;
console.log(TCurrentFrame);
}
}, 200);

}

<body>代码:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="600" height="600" id="Object">
        <param name="movie" value="./Flash.swf">
        <param name="wmode" value="transparent">
        <param name="loop" value="false">
        <param name="play" value="false"> 
        <param name="quality" value="high">
        <!--[if !IE]>-->
        <object type="application/x-shockwave-flash" data="./Flash.swf" width="600" height="600" id="Object">
        <param name="wmode" value="transparent">
        <param name="loop" value="false">
        <param name="play" value="false"> 
        <param name="quality" value="high">
        </object>
        <!--<![endif]-->
      </object>

j查询:

$("#button").on("click", function(){
ProgressBar();
})

我想要输出TotalFrameCurrentFrame,但函数SetInterval只显示一次结果。

控制台日志中的输出:

TotalFrames: 745
undefined
102

我怎么写这个?错误是什么?

也许是因为您没有像问题标题那样使用setInterval,而是在代码中使用setTimeout;)

您的ProgressBar函数使用的是setTimeout(),而不是setInterval()setTimeout()只触发一次超时。