User Guide

Building your first component 131
// The private member variable "__value" is publicly
// accessible through implicit getter/setter methods,
// Updating this property updates the needle's position
// when the value is set.
private var __value:Number = 0;
// This flag is set when the user drags the
// needle with the mouse, and cleared afterwards.
private var dragging:Boolean = false;
// Constructor;
// While required for all classes, v2 components require
// the contstructor to be empty with zero arguments.
// All initialization takes place in a required init()
// method after the class instance has been constructed.
function Dial() {
}
// Initialization code:
// The init() method is required for v2 components. It must also
// in turn call its parent class init() method with super.init().
// The init() method is required for components extending UIComponent.
function init():Void {
super.init();
useHandCursor = false;
boundingBox_mc._visible = false;
boundingBox_mc._width = 0;
boundingBox_mc._height = 0;
}
// Create children objects needed at start up:
// The createChildren() method is required for components
// extending UIComponent.
public function createChildren():Void {
dial = createObject("DialFinal", "dial", 10);
size();
}
// The draw() method is required for v2 components.
// It 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;
}