影片剪辑动态变量的属性?
我偶尔会使用 flash.display.MovieClip 类的这个有用的属性,
例如:
var mc:MovieClip = new MovieClip();
mc["myVariable"] = myAnotherMovieClip;
mc["myVariable2"] = true;
mc["myVariable3"] = new Array(0,0,1);
嗯,我想了解有关 movieclip 的这个“功能”的更多信息。我从一位同事那里了解到这一点,但并不真正知道这在 AS3 中被称为什么。
如果你们能提供帮助,我会非常高兴。
I do occasionally use this useful property of the flash.display.MovieClip class
for eg:
var mc:MovieClip = new MovieClip();
mc["myVariable"] = myAnotherMovieClip;
mc["myVariable2"] = true;
mc["myVariable3"] = new Array(0,0,1);
Well, I'd like to learn more about this 'feature' of movieclip. As I got to know this from a colleague and do not really know as to what this is called in AS3.
I'd be really glad if you people could help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在AS3中,MovieClip类是一个动态类。更多信息请参见:http://help.adobe.com /en_US/FlashPlatform/reference/actionscript/3/statements.html#dynamic
In AS3, the MovieClip class is a dynamic class. More informations here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/statements.html#dynamic
影片剪辑类是一个动态对象,它可以保存不同类型的变量(属性)。方括号是动态设置和访问对象属性的一种方式。
trace(mc["myVariable2"])
将输出true
;trace(mc.myVariable2)
也会输出true
。请注意,
mc["myVariable"] = myAnotherMovieClip
将创建一个属性来存储对 myAnotherMovieClip 的引用。The movie clip class is a dynamic object and it can hold different types of variables (properties). Square brackets are a way of dynamically setting and accessing the properties of an object.
trace(mc["myVariable2"])
would outputtrue
;trace(mc.myVariable2)
would outputtrue
as well.Note that
mc["myVariable"] = myAnotherMovieClip
would create a property that stores the reference to myAnotherMovieClip.