tags:

views:

128

answers:

5

I'm new to actionscript and I have noticed that many variable names in actionscript begin with an _ and I was wondering what the significance of it is?

+3  A: 

Private variables in Actionscript tend to have a _ in front of them. Then you have getter/setters without the _ to give them public access.

CookieOfFortune
+1  A: 

In Actionscript 2.0, _variable meant it was a built in property for an object. However, I stopped using Actionscript before 3.0 came out, so for all I know, it could have changed for 3.0.

DeadHead
+1  A: 

You're probably seeing a naming convention being used. There's no special significance from a language perspective.

Joseph
I figured it was a naming convention I wanted to know what it meant tho.
Anton
@Anton That's why I included the link, so you could understand why naming conventions are significant. However, from a language perspective, it is insignificant.
Joseph
+2  A: 

it is true, that in JavaScript, people used _ to denote "don't touch this value", since controlling access level in JavaScript is quite tricky ... making a variable really unaccessible from outside is quite a pain in the a** ...

in ActionScript 2.0 and 1, there is absolutely NO rule ... :D ... for example in class MovieClip, in ActionScript 2.0, there you have properties like _x, and _y ... yet the best thing is focusEnabled vs _focusrect, both booleans, one determining, whether the clip can be focused, the other whether it has a yellow rectangle, when focused ...

either this is really related to some stuff coming from the flash players insides, or it is just random ... note that there is _global, _root and _accProps and apart from that, it only appears on properties of TextField, MovieClip and Button ...

__ (two underscores) denotes magic in the flash player ... __resolve is quite a magic method ... and __proto__ is a magic property, if you will ... but also, this is not very consistent everywhere ...

now when it comes to ActionScript 3.0, the whole API does not use any underscores ... many people, including me, chose to denote private, protected and internal variables with $s and _s ... but this is a completely arbitrary naming convention that should make the code readable and prevent naming collisions ...

back2dos
+1  A: 

Simple - _{Your variable name} means that it's private.

In AS3, you define getters and setters like

public function get myVar ():String
{
    return _myVar;
}

this ends up being transparent outside of the class and showing as

myclass.myvar

Thus getters and setters in AS3 essentially look like obfuscated properties. So you need some way to differentiate - so you privates start with "_".

wb2nd