User Guide

922 Chapter 7: Creating Components
}
// 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;
}
// Remove the mouse events when the drag is complete,
// and clear the flag.
function mouseUpHandler()
{
dragging = false;
delete onMouseMove;
delete onMouseUp;
}
function mouseMoveHandler()
{
// Figure out the angle
if (dragging) {
var x:Number = _xmouse - width/2;
var y:Number = _ymouse - height/2;
var oldValue:Number = value;
var newValue:Number = 90+180/Math.PI*Math.atan2(y, x);
if (newValue<0) {
newValue += 360;
}
if (oldValue != newValue) {
value = newValue;
dispatchEvent( {type:"change"} );
}
}
}
}
Testing and exporting the Dial component
Youve created the Flash file that contains the graphical elements and the base classes and the class
file that contains all the functionality of the Dial component. Now it’s time to test the
component.
Ideally, you would test the component as you work, especially while youre writing the class file.
The fastest way to test as you work is to convert the component to a compiled clip and use it in
the components FLA file.
When youve completely finished a component, export it as a SWC file. For more information,
see “Exporting and distributing a component” on page 953.