Creating interactivity and visual effects 575
8. Select Frame 1 of the main Timeline, and select Window > Actions.
9. Enter the following code into the Actions panel:
this.createTextField("volume_txt", 10, 30, 30, 200, 20);
volume_mc.top = volume_mc._y;
volume_mc.bottom = volume_mc._y;
volume_mc.left = volume_mc._x;
volume_mc.right = volume_mc._x + 100;
volume_mc._x += 100;
volume_mc.handle_btn.onPress = function() {
startDrag(this._parent, false, this._parent.left, this._parent.top,
this._parent.right, this._parent.bottom);
};
volume_mc.handle_btn.onRelease = function() {
stopDrag();
var level:Number = Math.ceil(this._parent._x - this._parent.left);
this._parent._parent.song_sound.setVolume(level);
this._parent._parent.volume_txt.text = level;
};
volume_mc.handle_btn.onReleaseOutside = slider_mc.handle_btn.onRelease;
The startDrag() parameters left, top, right, and bottom are variables set in a
movie clip action.
10. Select Control > Test Movie to use the volume slider.
To create a sliding balance control:
1. Use the Rectangle Tool to draw a small rectangle on the Stage, approximately 30 pixels
high by 10 pixels wide.
2. Select the Selection Tool and double-click the shape on the Stage.
3. Press F8 to launch the Convert to Symbol dialog box.
4. Select the Button type, enter a symbol name of balance, and click OK.
5. With the button symbol selected on the Stage, enter an instance name of handle_btn in
the Property inspector.
6. Select the button, and select Modify > Convert to Symbol.
Be careful to select the movie clip behavior. This creates a movie clip with the button on
Frame 1.
7. Select the movie clip, and enter balance_mc as the instance name in the Property inspector.