User Guide

Creating interactivity and visual effects 191
6.
Enter the following event handlers:
slider_mc.knob_btn.onPress = function() {
startDrag(this._parent, false, this._parent.left, this._parent.top,
this._parent.right, this._parent.bottom);
};
slider_mc.knob_btn.onRelease = function() {
stopDrag();
};
slider_mc.onEnterFrame = function() {
this._parent.song.setVolume(this._x-this.left);
this._parent.volume_txt.text = this._x-this.left;
};
The startDrag() parameters left, top, right, and bottom are variables set in a clip action.
7.
Select Control > Test Movie to use the volume slider.
To create a sliding balance control:
1.
Drag a button to the Stage, and enter knob_btn as the instance name in the Property inspector.
2.
Select the button, and select Insert > Convert to Symbol. Select the movie clip property.
3.
Select the movie clip, and enter slider_mc as the instance name in the Property inspector.
4.
Select the button, and select Window > Development Panels > Actions.
5.
Enter the following code into the Actions panel:
slider_mc.top = slider_mc._y;
slider_mc.bottom = slider_mc._y;
slider_mc.left = slider_mc._x;
slider_mc.right = slider_mc._x+100;
slider_mc._x += 100;
slider_mc.onEnterFrame = function() {
if (this.dragging) {
trace((this._x-this.center)*2);
}
};
slider_mc.knob_btn.onPress = function() {
startDrag(this._parent, false, this._parent.left, this._parent.top,
this._parent.right, this._parent.bottom);
dragging = true;
};
slider_mc.knob_btn.onRelease = function() {
stopDrag();
dragging = false;
};
The startDrag() parameters left, top, right, and bottom are variables set in a clip action.
6.
Select Control > Test Movie to use the balance slider.
For more information about the methods of the Color class, see the Color class entry in
ActionScript Dictionary Help.