Yep!
The relevance of access modifiers has more to do with communication between different objects.
Imagine you have a Sister
class:
public class Sister extends Person
{
public var homework:String;
private var secretDiary:String;
public function Main()
{
//If you're not sure what this function does,
//check this out:
// http://developers.useflashpunk.net/t/help-with-calling-the-init-method/2132/8
homework = "Pages 2, 3 and 4";
secretDiary = "Benesh is so cute!";
}
}
And a Brother
class, with variables sistersHomework
and sistersDiary
.
Now, if a Brother
object asks a Sister
object for the homework, it works fine, since homework
is public, i.e.:
var brother:Brother = new Brother();
var sister:Sister = new Sister();
brother.sistersHomework = sister.homework;
//Works fine!
//brother.sistersHomework now is "Pages 2,3 and 4".
However, if the brother tries to read the sister’s secret diary, the compiler will throw an error. If you’re using FlashDevelop, the secretDiary variable won’t even appear on autocomplete! I.e.:
var brother:Brother = new Brother();
var sister:Sister = new Sister();
brother.sistersDiary = sister.secretDiary; //Throws error!
Is this helpful?