views:

181

answers:

4

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.

+1  A: 

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.

James Hay
I asked whether you could name MOVIECLIPs with "_" not members! Sorry!
Jenko
So what you actually meant was instance names not library symbols. Easy mistake to make and yes, again that's also fine. Hardly feel like this was worth a down vote!
James Hay
This did not deserve a -1, the poster answered your question and then made a recommendation based on best practice.
Richard Szalay
A: 

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

Jenko
Why do you post an answer to your own question? It's more appropriate to edit the question and add an SOLVED: or UPDATE section to it.
Luke
So that I can checkmark it as the answer, dummy!
Jenko
So, if I understand correctly, your participation on Stackoverflow is just about gaining reputation?
Luke
Wrong, if my answer is the best, then I should checkmark it so others know that it is the solution to my problem.
Jenko
+2  A: 

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.

fenomas
A: 

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.

PiPeep