Linus's Blanket

小辛的笔记

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

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 ) 时才会重新计算变量!

阅读更多
个人分类: Action Script
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

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

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭