Invalid Position
Invalid Position
internet.com home logo
 
Flash Jobs
 Top : Audio 

Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


» Level Intermediate

Added: : 2002-01-02
Rating: 8.70 Votes: 86
Hits: 4867

» Author
Primary goal in life is to play 'surf instrumental' music and program in Flash...

» Download
Download the files used in this tutorial.
Download (276 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!



Turn Flash in Desktop App or Widget. Win & Mac.



World's Favorite Flash Tool 200,000 users and growing!











internet.commerce
Be a Commerce Partner
 » Post A Job
 » Developer Jobs
 » High-Tech Jobs
 » Search For A Job
 » Post Your Resume
 » IT Jobs
 » Tech Careers
 » Invalid Position
 » Invalid Position
 » Invalid Position
 » Invalid Position
 » Invalid Position
 » Invalid Position
 
Invalid Position
Volume & Pan Slide Controls
Author: Joe Jabon |
 
Page 1
1

Volume and Pan Sliders<%BRK %><%BRK %><%BRK %><%BRK %>

The swf file

This tutorial will show you how to create slide controls that let you change the volume and panning of sound objects in a Flash. I have written this in the tradition of Object Oriented Programming and skipped most of the gory details behind the code and assume that everyone has their favorite ActionScript Reference manual close at hand.

To make it as simple as possible, I've broken it into four parts:
  • Creating the slider
  • Adding ActionScript to the slider
  • Creating and linking the sound object
  • Displaying the slider values
All set? Let's go!

Creating the slider

Part 1: Create a button
The first job will be to create a slide controller. To do this, we will be embedding a button instance inside a movie clip (to create a dragable button) and then embed that movie clip in another movie clip (to create the slider). Here's how it's done.

Note: The following steps should be not performed on the main timeline stage, but from within the library in edit symbol mode.

First, open the library and create a button symbol and name it button body. A small square (about 30 x 30) will do just fine.

Note: Size is not the issue at this point, but make sure that you center it to the stage!

While you're here, add over and down states the button and change the fill color of each.

Part 2: Create a drag button
Next we need to make the button dragable. To do this we will need to embed an instance of the button in a movie clip.

Again, open the library and create a new movie clip and name it drag button. Now, drag an instance of button body onto the drag button stage and center it.

On the stage, right click on the button instance and select Actions to open the Object Actions Panel. Click in the Object Actions Panel and add this ActionScript to the button instance:

drag instance pic

Part 3: Create a slider
Now that we have a dragable button, we can create a slide controller by embedding drag button in another movie clip.

Again, in the library, create another movie clip and name it slider. Create an additional layer in slider and name bottom layer bar and the top layer button.

Select the bar layer and draw a horizontal line. Use the info panel to make it exactly 100 pixels wide and use the align panel to center it to the stage, both horizontally and vertically.

Select the button layer and drag an instance of the drag button movie clip onto the stage. Use the info panel to resize it to 11 x 11 and use the align panel to center it to the stage, both horizontally and vertically. It should look like this: (minus the orange stuff)

slider pic
In order to finish our slider, we need to do one more thing, give the instance a name.
Select the drag button instance and use the instance panel to name it drag.
It should look like this:

drag instance pic

The slider should now be complete.

Note: All of this embedding so far should have been done in the movie clip symbols in the library, not on the main timeline. At this point there should be nothing on the main timeline stage.

Adding ActionScript to the slider

Now that we've finished creating the slider, we can exit the symbol edit mode and go back to the main timeline (ctrl+e or click Scene 1). Create 2 additional layers and name them text, sliders and scripts.
It should look like this:

layer1 pic

Select the sliders layer and 2 instances of the slider movie clip onto the stage. Position them so one is above the other and align them vertically to the stage. Select the top slider instance and use the instance panel to give it the name panSlider.

sliderPan1 pic

Select the bottom slider instance and use the instance panel to give it the name volSlider.

sliderVol1 pic

Now we just have to add some ActionScript to the slider instances. Right click on the volSlider instance, select Actions to open the Object Actions Panel and insert the following ActionScript.

sliderVol2 pic

Next, right click on the panSlider instance, select Actions to open the Object Actions Panel and insert the following ActionScript.

sliderPan2 pic

The sliders are ready for action. Now we need to create a sound object to control.

Creating and linking the sound object

There are a couple of significant changes in Flash 5 when it comes to dealing with audio files. One is the Sound object, which allows for much greater control of audio, thus allowing us to change the volume and pan values and the other is the way Library symbols can now be exported to the movie without being placed on any frame using the linkage potion. We'll start with linkage.

This tutorial uses a small wav file called tack1 which has already been imported. Open the Library and right click on tack1 to open the dropdown menu and select linkage.

linkage1 pic

This opens the Symbol Linkage Properties dialog box. Select the Export this symbol radio button and type in myMuzak.

linkage2 pic

This identifier allows us to reference the sound symbol in the same way that naming a movie clip instance allows you to control its properties.

The last thing we need to do is create a sound object. This sort of initialization should be done on the first frame of the movie.

Double click on frame 1 of the scripts layer to open the Frame Actions Panel and enter the following:

sound1 pic

The first line creates a sound object called 'mySound'.
The second line links 'myMuzak' to 'mySound'.
The third line tells 'mySound' to start at the beginning of the audio file and loop 999 times.

Test the movie. You should be able to change the volume and the pan values by moving the sliders.

Displaying the slider values

As a final touch, let's add a couple dynamic text fields to display the current volume and pan slider values. Create 2 dynamic text fields and give one variable the name panAt...

dynatext pic

and the other volAt.

dynatext2 pic

Test the movie. You should now have 2 text fields that constantly update the volume and pan slider values.

This concludes the tutorial. Enjoy!

Joe Jabon

1
Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10987654321Read or Post Comments

hardware central logo
Invalid Position
Invalid Position

HardwareCentral
Compare products, prices, and stores at Hardware Central!