User Guide

Implementing the component 159
Calls to the commitProperties() method occur before calls to the measure() method. This
lets you set property values that the
measure() method might use.
The typical pattern that you use for defining component properties is to define the properties
by using getter and setter methods, as the following example shows:
// Define a private variable for the alignText property.
private var _alignText:String = "right";
// Define a flag to indicate when the _alignText property changes.
private var bAlignTextChanged:Boolean = false;
// Define getter and setter methods for the property.
public function get alignText():String {
return _alignText;
}
public function set alignText(t:String):void {
_alignText = t;
bAlignTextChanged = true;
// Trigger the commitProperties(), measure(), and updateDisplayList()
// methods as necessary.
// In this case, you do not need to remeasure the component.
invalidateProperties();
invalidateDisplayList();
}
// Implement the commitProperties() method.
override protected function commitProperties():void {
super.commitProperties();
// Check whether the flag indicates a change to the alignText property.
if (bAlignTextChanged) {
// Reset flag.
bAlignTextChanged = false;
// Handle alignment change
}
}
As you can see in this example, the setter method modifies the property, calls the
invalidateProperties() and invalidateDisplayList() methods, then returns. The
setter itself does not perform any calculations based on the new property value. This design
lets the setter method return quickly, and leaves any processing of the new value to the
commitProperties() method.