AS3:类加载顺序

发布于 2024-10-02 10:33:30 字数 798 浏览 2 评论 0原文

我有一个关于 AS3 中的静态块的快速问题。

我有一个库,需要在执行任何应用程序逻辑之前静态初始化。如果我插入如下所示的静态代码块,这真的会在其他所有事情之前执行吗? (即:假设所有内容都将在应用程序启动之前完成,是否安全?)

package {

    import com.tkassembled.library.MyStaticLibrary;
    import com.tkassembled.library.MyWorker;

    import flash.display.Sprite;

    public class Application extends Sprite {

        // begin static code 
        /* initialize */ {
            MyStaticLibrary.worker = new MyWorker();
        }

        public function Application() {

        }
    }
}

我假设上述代码将以以下方式执行:

  1. 加载 Application 类,因为它是“主要可执行文件”。
  2. 加载 MyStaticLibraryMyWorker,执行其中的任何静态块。
  3. 执行Application内的静态块。
  4. 调用构造函数并开始工作。

有谁知道这是真的还是假的?我想我会构建一个应用程序来同时测试它:)

I had a quick question on static blocks in AS3.

I have a library that requires initialization statically before any application logic is executed. If I insert a static code block like the following, will this truly be executed before everything else? (ie: is it safe to assume that everything will be setup before the application starts?)

package {

    import com.tkassembled.library.MyStaticLibrary;
    import com.tkassembled.library.MyWorker;

    import flash.display.Sprite;

    public class Application extends Sprite {

        // begin static code 
        /* initialize */ {
            MyStaticLibrary.worker = new MyWorker();
        }

        public function Application() {

        }
    }
}

I would assume that the above code would execute in the following fashion:

  1. Load Application class, as it is the 'main executable'.
  2. Load MyStaticLibrary and MyWorker, executing any static blocks in them.
  3. Execute the static blocks within Application.
  4. Call the constructor and get things going.

Does anyone know if this is true or not? I guess I'll build an application to test it all out in the meantime :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的心境我的脸 2024-10-09 10:33:30

做了作业,这里是执行顺序:

[16] Application static block executed.
[16] MyLibrary static blocks invoked. 
[16] MyWorker static blocks
[16] MyWorker constructor called. 
[16] MyLibrary.worker set.
[17] Application constructor executed.

它确实有助于理解事情是如何工作的:)

你可以在这里获取我的实验文件:http ://bit.ly/aKwqp6

Did the homework, here is the execution order:

[16] Application static block executed.
[16] MyLibrary static blocks invoked. 
[16] MyWorker static blocks
[16] MyWorker constructor called. 
[16] MyLibrary.worker set.
[17] Application constructor executed.

It really helps to understand how things work :)

You can get my experiment files here: http://bit.ly/aKwqp6

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文