【问题标题】:Actionscript3 static variables inside functions函数内的 Actionscript3 静态变量
【发布时间】:2013-10-15 08:13:35
【问题描述】:

我可以在 actionscript 3 中执行此操作吗?调用定时器函数时,计数器只定义一次

function timer(e:TimerEvent):void
{
    static var counter=1;
    trace("Times: " + counter );
}

【问题讨论】:

    标签: actionscript-3 flash


    【解决方案1】:

    怎么样:

    function timer(e:TimerEvent):void
    {
        this.counter = this.counter || 0;
        this.counter ++;
        trace("Times: " + this.counter );
    }
    

    【讨论】:

    • @Alex 这一行:this.counter = this.counter || 0; 检查是否在计时器函数运行的范围内定义了计数器,如果已定义则使用它,如果未定义则创建一个新的。在这之后只是增加它..
    猜你喜欢
    • 1970-01-01
    • 2013-11-04
    • 2016-08-30
    • 2016-04-27
    • 2010-11-02
    • 2010-09-16
    • 2016-07-26
    • 2011-06-29
    • 1970-01-01
    相关资源
    最近更新 更多