AS3:类加载顺序
我有一个关于 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() {
}
}
}
我假设上述代码将以以下方式执行:
- 加载
Application
类,因为它是“主要可执行文件”。 - 加载
MyStaticLibrary
和MyWorker
,执行其中的任何静态块。 - 执行
Application
内的静态块。 - 调用构造函数并开始工作。
有谁知道这是真的还是假的?我想我会构建一个应用程序来同时测试它:)
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:
- Load
Application
class, as it is the 'main executable'. - Load
MyStaticLibrary
andMyWorker
, executing any static blocks in them. - Execute the static blocks within
Application
. - 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
做了作业,这里是执行顺序:
它确实有助于理解事情是如何工作的:)
你可以在这里获取我的实验文件:http ://bit.ly/aKwqp6
Did the homework, here is the execution order:
It really helps to understand how things work :)
You can get my experiment files here: http://bit.ly/aKwqp6