User Guide

Building your first component 921
size();
}
// The draw method is invoked after the component has
// been invalidated, by someone calling invalidate().
// This is better than redrawing from within the set function
// for value, because if there are other properties, it's
// better to batch up the changes into one redraw, rather
// than doing them all individually. This approach leads
// to more efficiency and better centralization of code.
function draw():Void {
super.draw();
dial.needle._rotation = value;
}
// The size method is invoked when the component's size
// changes. This is an opportunity to resize the children,
// and the dial and needle graphics.
function size():Void {
super.size();
dial._width = width;
dial._height = height;
// Cause the needle to get redrawn, in case it needs it
invalidate();
}
// This is the getter/setter for the value property.
// The [Inspectable] metadata makes the property appear
// in the Property inspector. This is a getter/setter
// so that you can call invalidate and force the component
// to redraw, when the value is changed.
[Bindable]
[ChangeEvent("change")]
[Inspectable(defaultValue=0)]
function set value (val:Number)
{
__value = val;
invalidate();
}
function get value ():Number
{
return twoDigits(__value);
}
function twoDigits(x:Number):Number
{
return (Math.round(x * 100) / 100);
}
// Tells the component to expect mouse presses
function onPress()
{
beginDrag();