为什么在 Flash IDE 中编译时我无法在 addChild 之前访问 Sprite 构造函数中的阶段,而如果在 Flex 中编译则可以正常工作?

发布于 2024-08-30 11:37:44 字数 672 浏览 2 评论 0原文

我创建了这个简单的类(省略了包指令和导入),

public class Viewer extends Sprite {
    public function Viewer():void {
         trace(stage);
    }
}

然后在 Flash IDE 中我在第一帧中导入了这个 AS:,

import Viewer
var viewer = new Viewer();
stage.addChild(viewer);
trace(viewer.stage);

这按我的预期工作:构造函数中调用的第一个跟踪说 stage 是“null”,因为我还没有还可以将查看器添加到 DisplayObjectContainer。第二个输出舞台对象。

因此,我使用 AXDT eclipse 插件创建了一个项目,我仅重新创建并编译了第一个类(丢弃了 Flash IDE 中使用的 AS 初始化脚本,因为不需要),并且在第一个跟踪中...哇...舞台是充满了舞台对象。

在我看来,AXDT(Flex4 SDK 开源)使用的编译器在构造它之前添加了类...(!?)..到已附加到舞台的 DisplayObjectContainer。

我想了解如何使用 Flash IDE 中的编译器重现此行为,以便我可以直接访问构造中的 Stage。

I've created this simple class (omissing package directive and imports)

public class Viewer extends Sprite {
    public function Viewer():void {
         trace(stage);
    }
}

then in Flash IDE I import in first frame this AS:

import Viewer
var viewer = new Viewer();
stage.addChild(viewer);
trace(viewer.stage);

and this works as I expected: the first trace called in constructor say stage is "null" because I haven't yet add viewer to a DisplayObjectContainer. The second one output the stage object.

So I created a project using AXDT eclipse plugin, I've recreated and compiled only the first class (trashed the AS init script used in Flash IDE because is not needed) and on the first trace ... wow ... the stage is filled with the stage Object.

I seems to me that the compiler used by AXDT (Flex4 SDK open source) add the class... before construct it (!?).. to a DisplayObjectContainer already attached to a Stage.

I want to understand how can reproduce this behaviour using compiler in Flash IDE so I can directrly access Stage in construction.

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

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

发布评论

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

评论(1

↙温凉少女 2024-09-06 11:37:44

stage 在调用构造函数之前在文档类中定义。由于您将 Viewer 编译为 Document 类,因此会发生这种情况。

stage is defined in the Document Class before the constructor is invoked. Since you compile Viewer as Document class this happens.

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