从 AS2 到 AS3 _root 相当于什么?

发布于 2024-07-09 08:22:40 字数 819 浏览 3 评论 0原文

我正在尝试学习 Actionscript 2 或 3,通过 AS2,我最终通过反复试验发现,我可以获取任何命名实例,并使用其名称的字符串对其进行修改,

var theinstance = "titletext"; // actually exctracted from an array
_root[theinstance].htmlText = "New text with <b>HTML!</b>";

但在尝试将代码转换为 AS3 _root 时 不再存在。 根据迁移文档,它以某种方式被flash取代.display.DisplayObject.stage 但显然这不是如何做到的:

flash.display.DisplayObject.stage[theinstance].htmlText = "New text with <b>HTML!</b>";

这也不是:

flash.display.DisplayObject.stage.getChildByName(theinstance).htmlText = "New text with <b>HTML!</b>";

How do I get a child by name in actionscript 3?

I'm trying to learn Actionscript 2 or 3, with AS2 I eventually figured by trial and error that I could get any named instance and modify it using a string with its name using

var theinstance = "titletext"; // actually exctracted from an array
_root[theinstance].htmlText = "New text with <b>HTML!</b>";

but when trying to convert the code to AS3 _root doesn't exist anymore. According to the migration doc it is somehow replaced by flash.display.DisplayObject.stage but apparently this is not how to do it:

flash.display.DisplayObject.stage[theinstance].htmlText = "New text with <b>HTML!</b>";

and neither is this:

flash.display.DisplayObject.stage.getChildByName(theinstance).htmlText = "New text with <b>HTML!</b>";

How do I get a child by name in actionscript 3?

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

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

发布评论

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

评论(2

长安忆 2024-07-16 08:22:40

只需使用“root”(无下划线)或“stage”,具体取决于您想要执行的操作。

但是 - 为什么不只存储对数组中 textField 的引用而不是字符串呢?

Just use either "root" (no underscore) or "stage" depending on exactly what you want to do.

However - Why not just store a reference to the textField in the array instead of a string?

白昼 2024-07-16 08:22:40

“flash.display.DisplayObject”实际上并不是您调用的实际代码的一部分。 相反,文档告诉您 stage 属性在 DisplayObject 类的任何实例上都可用 - 例如,movieClip 或 sprite。

例如,如果您有一个名为 foo 的 movieClip,您可以使用以下命令引用舞台:

foo.stage

并从那里开始。

foo.stage.someRootLevelObject.htmlText = "Pretty <b>easy</b>";

"flash.display.DisplayObject" is not literally part of the actual code that you call. Rather, the documentation is telling you that the stage property is available on any instance of the DisplayObject class -- for example, a movieClip or a sprite.

For example, if you have a movieClip named foo, you could reference the stage with:

foo.stage

and go from there.

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