PDA

View Full Version : class property names question


Navarone
09-29-2009, 04:52 PM
In reading Learning Actionscript 3.0, the author indicates in a side note that it is common to precede class property names with an underscore, but it is not required. I am also reading through Essential Actionscript 3.0 by Colin Moock and I can't find anywhere that this kind of distinction is made. What is the correct method? What are class property names, variables? :confused:

EvLSnoopY
09-29-2009, 07:37 PM
Class names by convention begin with a capitol letter for example:

Filename: Vehicle.as

package com.JynxStudio {

import flash.display.Sprite;

public class Vehicle extends Sprite { // Class name is "Vehicle".

public function Vehicle() { // The classes' constructor function

}
}
}

Navarone
09-29-2009, 07:49 PM
Can you explain how your example answers my two questions. I guess I am confused when the author declares class "property" name and the use of the underscore.

snickelfritz
09-29-2009, 08:22 PM
Using the underscore for AS3 class properties, which are variables, is not required.
It's more or less a practice that can make your class easier to interpret.

BTW, the leading underscore was used for native AS2 properties, such as _x, _alpha, etc...

Navarone
09-29-2009, 08:41 PM
Using the underscore for AS3 class properties, which are variables, is not required.
It's more or less a practice that can make your class easier to interpret.

BTW, the leading underscore was used for native AS2 properties, such as _x, _alpha, etc...

So if you wanted to distinguish public vars from private vars throughout your code you could set all public vars with the underscore and all private vars with out the underscore or vise-versa. Would that be a correct assessment?

I did see that _x, _alpha have now be replaced with just ".x" or ".alpha". There are some new distinctions between the usage of "_root" and "root" in AS3 which I don't fully understand yet either.

EvLSnoopY
09-29-2009, 10:50 PM
So if you wanted to distinguish public vars from private vars throughout your code you could set all public vars with the underscore and all private vars with out the underscore or vise-versa. Would that be a correct assessment?
Yes that would be a correct assessment.

ASWC
09-30-2009, 01:53 AM
What are class property names, variables? :confused: Yes and no. A property can be a member variable declared public or a getter/setter.