循环功能

时间:2011-05-27 13:59:19

标签: javascript jquery html flash

您好我在下面有这个代码,基本上在显示第一个.swf第二个.swf节目的25秒后。现在我希望在12秒后回到第一个。然后以相同的方式循环。第1次瑞士法郎第1次瑞士法郎第1次瑞士法郎......

<script type="text/javascript">
            var flashvars = {};
            flashvars.xml = "config.xml";
            flashvars.font = "font.swf";
            var attributes = {};
            attributes.wmode = "transparent";
            attributes.id = "slider";
            swfobject.embedSWF("cu3er.swf", "cu3er-container", "960", "400", "9", "expressInstall.swf", flashvars, attributes);

setTimeout(function() {
  swfobject.embedSWF("printmachine.swf", "cu3er-container", "960", "400" , "0");
}, 25000);
</script>

我该怎么做?

由于

3 个答案:

答案 0 :(得分:1)

您可以使用具有适当延迟和回调方法的setTimeout()。

<script type="text/javascript">
function aaa() {
  var flashvars = {};
  flashvars.xml = "config.xml";
  flashvars.font = "font.swf";
  var attributes = {};
  attributes.wmode = "transparent";
  attributes.id = "slider";
  swfobject.embedSWF("cu3er.swf", "cu3er-container", "960", "400", "9", "expressInstall.swf", flashvars, attributes);
  setTimeout(bbb, 25000);
}

function bbb() {
  swfobject.embedSWF("printmachine.swf", "cu3er-container", "960", "400" , "0");
  setTimeout(aaa, 12000);
}
</script>

答案 1 :(得分:1)

以下将SWF的显示分为两个不同的功能。每个函数都通过超时调用另一个函数。因此它将显示SWF1并将SWF2方法排成25秒。当它运行时,它加载SWF2并将SWF1功能排成12秒。然后它将从那里循环交替每个SWF。

你可以重构它,但这个基本想法应该可以解决问题。

<script type="text/javascript">
    function showSwf1(){
        swfobject.embedSWF("cu3er.swf", "cu3er-container", "960", "400", "9", "expressInstall.swf", flashvars, attributes);
        setTimeout(showSwf2, 25000);
    }

    function showSwf2(){
        swfobject.embedSWF("printmachine.swf", "cu3er-container", "960", "400" , "0");
        setTimeout(showSwf1, 12000);
    }

    var flashvars = {};
    flashvars.xml = "config.xml";
    flashvars.font = "font.swf";
    var attributes = {};
    attributes.wmode = "transparent";
    attributes.id = "slider";
    showSwf1();
</script>

N.B。代码未经测试,因此对轻微的错别字或任何事情道歉。虽然在我的头脑中处理后工作。 ; - )

答案 2 :(得分:1)

将嵌入式swf动作转换为一个函数,这将无限循环,并允许您将任何其他SWF添加到数组中,如果您希望将来扩展它:

<script type="text/javascript">
    var swfs = [{swf:"cu3er.swf",delay:25000, flashvars:{xml:"config.xml",font:"font.swf"},attributes:{wmode:"transparent",id:"slider"}}, 
                {swf:"printmachine.swf",delay:12000,flashvars:{},attributes:{}}];
    loadSWF(0);        

    function loadSWF(ind){
        if(ind >= swfs.length)ind = 0;
        swfobject.embedSWF(swfs[ind].swf, "cu3er-container", "960", "400", "9", "expressInstall.swf", swfs[ind].flashvars, swfs[ind].attributes);
        setTimeout("loadSwf("+(ind+1)+")", swfs[ind].delay);
    }
</script>