PDA

View Full Version : Basic question about underscore


NeoDreamer
01-03-2007, 08:11 PM
example: _root._xmouse;

Can somebody explain to me when to use underscore _ and when not to use underscore?

TheCanadian
01-03-2007, 08:20 PM
The underscore is just part of the property name. There's no rule that tells you when to use it, you just have to know which properties have it and which do not.

Luckily this odd convention is removed in AS3.

Dazzer
01-04-2007, 01:36 AM
actually i think all properties has _ in AS2.

only methods do not have the underscore.

It is a simply a convention. You don't necessarily have to follow it. What matters most is that you follow A convention, and stick to it throughout the project.

TheCanadian
01-04-2007, 01:43 AM
No, the only properties that use an underscore are some selected MovieClip properties; I think they are getter/setter.

Dazzer
01-04-2007, 01:47 AM
that explains abit.

doesn't matter. We can conclude that AS2 naming conventions are rather crappy, and move on to AS3 = grins =

NeoDreamer
01-04-2007, 07:04 PM
So you're all saying that the underscore can be ditched and the whole program will still work?

bodyvisual
01-04-2007, 07:52 PM
no. AS3 loses the _

box_mc._x != box_mc.x

in AS2, box_mc.x would create a var called x inside box_mc.

jjcorreia
01-04-2007, 07:54 PM
Think of underscore as a letter like a or c. You can tack it on to anything

my_var
_somepropertyI_made

As mentioned properties in AS 2.0 and before were named with an underscore in front. Its just a naming convention and AS 3.0 is ditching it since its not really needed.

TheCanadian
01-04-2007, 08:17 PM
So you're all saying that the underscore can be ditched and the whole program will still work?
No, not at all.