User Guide

132 Creating Components
// 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.
// The size() method is required for components extending UIComponent.
function size():Void {
super.size();
dial._width = width;
dial._height = height;
// Cause the needle to be redrawn, if necessary.
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();
}
// When the dial is pressed, the dragging flag is set.
// The mouse events are assigned callback functions.
function beginDrag()
{
dragging = true;
onMouseMove = mouseMoveHandler;
onMouseUp = mouseUpHandler;