我无法操作嵌套在另一个符号中的符号

I am not able to manipulate a Symbol that is nested within another Symbol

我是一名新程序员,也是第一次提问。我正在开发一个显示数学问题的程序,其中每个数字都由一个符号表示。为了更容易操纵问题的大小,我想制作一个 Symbol "problem" 并将 "digit" 的 Symbols 放入其中。 "problem" 是舞台上 Symbol "Problem" 实例的名称。不同的数字是符号 "Number" 的实例,并像这样命名 "digit01, digit02, digit03, digit11..." 直到 "digit33" 我希望程序循环遍历所有数字,使它们在第一帧停止。

这是我的代码的相关部分:

for (var u: int = 0; u < 4;u++)
{
   for (var v: int = 1; v < 4;v++)
   {
       this["problem.digit" + u + v].gotoAndStop(1);
   }
}

当我 运行 这样做时,我得到错误 #1069。 "problem.digit01 not found on Main_Math and there is no default value."

顺便说一句,当我像这样单独写数字时它会起作用:

problem.digit01.gotoAndStop(1);
problem.digit02.gotoAndStop(2);

等..

感谢您提供的任何指导。谢谢!

地址不是那样工作的。您无法通过单个 [] 操作解决 child 的 children。此外,最好使用 getChildByName 方法,因为点语法访问仅适用于发布选项 "automatically declare stage instances".

for (var u: int = 0; u < 4;u++)
{
    for (var v: int = 1; v < 4;v++)
    {
        // Get a reference to a child and typecast it as MovieClip.
        var aDigit:MovieClip = problem.getChildByName("digit" + u + "" + v) as MovieClip;
        aDigit.gotoAndStop(1);
    }
}

让我们解释一些事情。

首先,MovieClip 是一个动态的 class,这意味着您可以读取和写入其实例成员而无需实际声明它们(此处解释了点和括号语法之间的区别 Using . or [ ] to access Object properties - what's the difference? ):

var M:MovieClip = new MovieClip;

trace(M['a']); // undefined, no error raised
M['a'] = 1;
trace(M['a']); // 1
trace(M.a]);   // 1

其次,MovieClip 是一个 DisplayObjectContainer,因此它可以包含 children。这些 children 有名字,你可以通过调用 getChildByName("child name goes here") 方法来引用它们,并且不要忘记对结果进行类型转换,因为有各种各样的 children 所以他们默认情况下由其基础 DisplayObject class 键入。 child 名称 与 object 成员名称 不同(尽管如前所述,"automatically declare stage instances" 分配 child 引用到幕后同名变量):

// We proceed working with M from above.

// Lets create a child for M.
var C:MovieClip = new MovieClip;

// MovieClip C has a name "D" as of now.
C.name = "D";

// C named "D" becomes a child of M.
M.addChild(C);

trace(M.C); // undefined, because C is not a member of M object, it's just a local variable
trace(M.D); // undefined, because D is the name of MovieClip which is child of M MovieClip but not a member of M objest.
trace(M.getChildByName("C")); // null, because M has no children with name "C".
trace(M.getChildByName("D")); // [object MovieClip] because there is indeed a child with the name "D" inside of M.

// We create a field with the name "E" inside M object.
M.E = C;
trace(M.getChildByName("E")); // null, because M has no children with name "E".
trace(M.E); // [object MovieClip] because M now contains a field E with the reference to MovieClip C named "D".