动态访问 Flash ActionScript 2 中的嵌套影片剪辑
我有一个想要访问的嵌套影片剪辑实例。 影片剪辑的路径由两个变量定义(类似于行和列)。
我已经像这样动态访问父影片剪辑:
eval("row" + ActiveRow)
现在我想动态访问 row(#) 的名为 let(#) 的子级之一。
以下是我完成任务的最佳猜测(都不起作用):
var i:number;
eval("行" + ActiveRow + ".let" + i) 或者 eval("row" + ActiveRow).eval("let" + i)
非常感谢您的努力和可能的解决方案。
I have a nested movie clip instance that I want to access. The path to the movie clip is defined by two variables ( similar to a row and column).
I am already dynamically accessing the parent movie clip like this:
eval("row" + ActiveRow)
Now I want to access one of row(#)'s children called let(#) dynamically.
Here are my best guesses at accomplishing the task (neither one works):
var i:number;
eval("row" + ActiveRow + ".let" + i)
or
eval("row" + ActiveRow).eval("let" + i)
Thanks a lot for your effort and possible solution..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以尝试
更好的是,如果你创建实例时将它们放入一个数组中...那么也许
调用它,
你可以通过显然根据情况来 将你的MovieClips添加到数组中可能有不同的逻辑,但是本质上,这是存储对 MovieClip 的引用的更好方法。
you could try
What would be better though is if when you create the instances you put them in an array... so maybe
you can then call it by
Obviously depending on the situation there could be different logic to adding your MovieClips to an Array but essentially it's a much nicer way to store references to your MovieClips.
访问父影片剪辑后,只需索引子影片剪辑即可。 ActionScript 2 不要求您使用
eval
函数来查找动态属性。 只需使用对象和[]
(数组)运算符来索引所需的变量。如果您的“row”对象位于当前影片剪辑的根目录中,则只需使用 _root[ "row" + ActiveRow ][ "let" + i ] 即可。
但是,由于您已经通过
eval("row"+ActiveRow)
获得了初始影片剪辑,因此您可以使用此对象来获取下一个级别。 例如,eval("row" + ActiveRow)[ "let" + i ]
。Flash 大量借鉴了 JavaScript,与 JavaScript 一样,每个对象本质上都是一个哈希表。 使用点运算符相当于对固定字符串使用 [](数组)运算符。
Once you access the parent movie clip, simply index into the child. ActionScript 2 does not require you to use the
eval
function for looking up dynamic properties. Simply use the object and the[]
(array) operators to index the desired variable.If your "row" objects are in the root of the current movie clip, you could simply use
_root[ "row" + ActiveRow ][ "let" + i ]
.However, since you already have the initial movieclip via
eval("row"+ActiveRow)
, you can use this object to get the next level down. For example,eval("row" + ActiveRow)[ "let" + i ]
.Flash borrows heavily from JavaScript, and like JavaScript, every object is essentially a hash table. Using the dot operator is equivalent to using the [] (array) operator with a fixed string.
首先,您似乎正在使用表格数据结构,因此一种简单的方法是创建一个二维数组并仅将影片剪辑存储在其中。 然后就可以通过索引进行查找了。
或者,您可以命名每个影片剪辑(使用 name 属性),并使用 getChildByName。
IE getChildByName("行"+i).getChildByName("列"+i)。
First of all, it seems like you're using a tabular data structure, so one easy way would be to create a two-dimensional array and just store the movie clips in there. Then you can do lookups by index.
Alternatively, you name each of your movie clips (using the name property), and use getChildByName.
I.E getChildByName("row"+i).getChildByName("column"+i).