动作3的init() [英] actionscript 3 init()

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

问题描述

我经常看到一个init()AS3类的构造函数中,有时甚至是唯一的code在构造函数中。为什么要做到这一点,如果你可以简单地使用构造函数本身初始化类它是有用的?

 包
{

    进口flash.display.Sprite;

    公共类实例扩展Sprite
    {

        公共函数实例()
        {
            在里面();
        }

        公共职能的init():无效
        {

         //这里初始化

        }

    }

}
 

解决方案

在ActionScript 3中,构造函数code是永远跨preTED而不是编译。我相信移动code成一个init()函数可能允许它被编译和优化

<一个href="http://blog.pixelbreaker.com/flash/as30-jit-vs-inter$p$pted/">http://blog.pixelbreaker.com/flash/as30-jit-vs-inter$p$pted/

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

        }

    }

}

解决方案

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-interpreted/

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

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