是“_”吗? 为影片剪辑名称保留前缀?

发布于 2024-07-12 08:10:45 字数 211 浏览 4 评论 0原文

是否可以使用“_”下划线前缀作为您自己的MovieClip名称?(AS2)

即您可以将创建/附加的MovieClip命名为“_feature”或“_bug” ?

通常,这是为内部属性保留的,例如_x_visible

Is it possible to use the "_" underscore prefix for your own MovieClip names? (AS2)

i.e. Can you name a created/attached MovieClip "_feature" or "_bug" ?

Typically this is reserved for internal properties like _x or _visible.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

吖咩 2024-07-19 08:10:45

“_”前缀没有技术意义 - 您可以将其用作影片剪辑、文本字段或任何其他您喜欢的变量或方法的名称。

作为一种约定,“内置”属性的名称(如 _x_visible 等)过去很常见以下划线开头,但它们停止了在 v6 或 v7 周围执行此操作,因此许多后续属性(例如 filterstransform)不使用它。 此外,他们还使用(我相信在 AS3 中仍然使用)多个下划线来表示他们不希望人们被绊倒的内部名称(例如 __proto__)。

过去还有一个相当广泛的约定,即在要私有的属性或方法前面添加 $ ,因为将它们声明为私有没有任何效果。 您在组件中经常看到这种情况。

The "_" prefix has no technical significance - you can use it your own names for MovieClips, text fields, or any other variable or method you like.

As a convention, it used to be common for the names of "built in" properties (like _x, _visible, etc.) to begin with an underbar, but they stopped doing this around v6 or v7, so many later properties (filters, transform for example) don't use it. Also, they've used (and still use I believe, in AS3) multiple underbars for internal names they don't want people to trip over (like __proto__).

There also used to be a fairly widespread convention to prepend $ to properties or methods intended to be private, since declaring them to be private doesn't have any effect. You see this a lot in components.

妄司 2024-07-19 08:10:45

是的,这很好。 不太确定你应该这样做,但如果你有这样的情况,它就不会出错。 我倾向于保留 _ 作为类的私有成员的前缀。

Yes this is fine. Not really sure you should be doing it but if you have a case for it it won't error out. I tend to reserve _ to prefix private members of a class.

想念有你 2024-07-19 08:10:45

是的,可以使用像_myclip这样的MovieClip名称,您可以静态this._myclip或动态引用它。 这个["_"+"myclip"]

Yes it is possible to use MovieClip names like _myclip, you can reference it statically this._myclip or dynamically too. this["_"+"myclip"]

§普罗旺斯的薰衣草 2024-07-19 08:10:45

这很好,但正确的 as3 做法是仅将“”用于内部、私有/受保护的变量,然后编写不带“”的 getter 和 setter。

例如:

private var _word:String = "something"

public function get word():String {
     return _word
}

public function set word(a_word:String):void {
     _word = a_word
}

有点冗长,但它是一个很好的 API。

It is fine, but proper as3 practice is to use the "" for only internal, private/protected variables, and then write getters and setters without the "".

eg:

private var _word:String = "something"

public function get word():String {
     return _word
}

public function set word(a_word:String):void {
     _word = a_word
}

A little verbose, but it makes for a nice API.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文