AS中setInterval()的参数传递注意~

Action Script 专栏收录该内容
3 篇文章 0 订阅

ActionScript中,setInterval()的标准语法:
                setInterval( function, interval [, param1 ... , paramN ] )
        其中param1...paramN即为给function传递的参数。不过,请看下示例:

        function fun1(sName:String, sMessage:String):Void{
                    trace("Hello,"+sName+". "+sMessage);
        } // fun1 

       function fun2():Void{
                        sNameParam="Steve";
                        sMessage="How are you?";
        } // fun2

        var sNameParam:String = "Linus";
        var sMessageParam:String="How do you do.";
        var nInterval1:Number = setInterval( fun1, 1000, sNameParam, sMessageParam );
        var nInterval2:Number = setInterval(fun2, 2000);

        猜想一下结果,是不是:
                      Hello, Linus. How do you do?
                      Hello, Steve. How are you?
                      Hello, Steve. How are you?
                      ……

         正确结果是!
                      Hello, Linus. How do you do?
                      Hello, Linus. How do you do?
                      Hello, Linus. How do you do?
                      ……

        只有当再次调用setInterval( fun1, 1000, sNameParam, sMessageParam ) 时才会重新计算变量!

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值