I see a lot of confusion around the web about access modifiers, so I am going to give a brief explication about them.
First, if you noticed the post title, you’ll see I wrote AS3 in brackets because access modifiers have not been introduced with AS3, but AS3 finally featured access modifiers.
As far as I can remember, access modifiers came from C, or at least I started studying them when I was programming with C.
Acess modifiers are anguage keywords for specifying the visibility of classes and members, that means they determine which code may access classes and class members.
Just think about a bartender in a exclusive pub that may require membership, and everything will be easier.
public (available to all code): allows access from every class… the bartender will attend everyone, no matter where he’s coming from
internal (available within the same package): allows Classes sharing this package access… the bartender will attend only people somehow related with the pub (workers that built it, people involved in furnishing, and so on)… this definition may lead to misunderstandings, so let’s say access is limited exclusively to classes defined within the current project.
protected (availabile within the same class and subclasses): allows subclasses access… the bartender will only attend customers with membership and their sons
private (available only within the same class): allows access only by the same class… the bartender will only attend customers with membership
Now the big question: is it so important to use the right access modifier?… I have to say in most small projects that you’re sure you’ll be the only one using them, you can define everything as public and forget about the rest, but obviously if you are looking for reusability and portability, you should pay attention to access modifiers.