从 AS2 到 AS3 _root 相当于什么?
我正在尝试学习 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需使用“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?
“flash.display.DisplayObject”实际上并不是您调用的实际代码的一部分。 相反,文档告诉您 stage 属性在 DisplayObject 类的任何实例上都可用 - 例如,movieClip 或 sprite。
例如,如果您有一个名为 foo 的 movieClip,您可以使用以下命令引用舞台:
并从那里开始。
"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:
and go from there.