我正在尝试学习 Actionscript 2 或 3,通过 AS2,我最终通过反复试验发现我可以获取任何命名实例并使用名称的字符串对其进行修改
var theinstance = "titletext"; // actually exctracted from an array
_root[theinstance].htmlText = "New text with <b>HTML!</b>";
但是当尝试将代码转换为 AS3 时,_root
不再存在。根据migration doc它以某种方式被 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>";
如何在 ActionScript 3 中按名称获取子项?
最佳答案
只需使用“root”(无下划线)或“stage”,具体取决于您想要执行的操作。
但是 - 为什么不只存储对数组中 textField 的引用而不是字符串?
关于actionscript-3 - 从 AS2 到 AS3 _root 相当于什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/305320/