Is it possible to have a property with a public getter and protected setter?
I have the following code:
public class Mob extends Sprite {
// snip
private var _health:Number; // tried making this protected, didn't work
public function get health():Number { return _health; }
protected function set health(value:Number):void {
_health = value;
}
// snip
public function takeDamage(amount:Number, type:DamageType, ... additionalAmountAndTypePairs):void {
var dmg:Number = 0;
// snip
var h:Number = this.health; // 1178: Attempted access of inaccessible property health through a reference with static type components.mobs:Mob.
this.health = h - dmg; // 1059: Property is read-only.
}
}
I did have this.health -= dmg;
but I split it out to get more details on the compiler errors.
I don't understand how the property would be considered read-only within the same class. I also don't understand how it's inaccessible.
If I make the backing field, getter, and setter all protected, it compiles but it's not the result I want; I need health to be readable externally.