Looking closely at setters & getters

AS3 has a mechanism for defining setters & getters for the member variables (pardon, properties).

private var _property:uint
public function set property(value:uint):void
    _property = value;
public function get property():uint
    return _property;

Recently, I’ve bumped into the the strange thing: if you change directly the value:

 _property = 17;

this won’t generate propertyChangeEvent and all you bound variables won’t be notified about the change. So, instead when you need to notify others about the change, you have to do this:

 property = 17;

This will cause the setter to be executed and propertyChangeEvent will be dispatched.

Leave a Reply