动作脚本 3 init() [英] actionscript 3 init()

查看:20
本文介绍了动作脚本 3 init()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常在 AS3 类的构造函数中看到 init(),有时甚至是构造函数中的唯一代码.如果您可以简单地使用构造函数本身来初始化一个类,为什么这样做会有用?

I have often seen an init() within the constructor of AS3 classes, sometimes even being the only code in the constructor. Why would it be useful to do this, if you could simply use the constructor function itself to initialize a class?

package 
{

    import flash.display.Sprite;

    public class Example extends Sprite
    {

        public function Example()
        {
            init();                 
        }

        public function init ( ):void
        {

         //initialize here

        }

    }

}

推荐答案

在 ActionScript 3 中,构造函数代码总是被解释而不是编译.我相信将代码移动到 init() 函数中可能会使其被编译和优化.

In ActionScript 3, constructor code is always interpreted rather than compiled. I believe moving the code into an init() function may allow it to be compiled and optimized.

http://blog.pixelbreaker.com/flash/as30-jit-vs-解释/

这篇关于动作脚本 3 init()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆