Our Flash tutorials provide you with step-by-step instructions on how to create beautiful Flash animations and integrate them into your website.  Home Flash & Swish Flash Tutorials Balance Slider or Panning Effect
Your Ad Here

Balance Slider or Panning Effect


Download .fla - 877 Kb zipped Flash® file

Using the predefined Objects for sound under Frame Actions, you can manipulate the volume and pan of a particular sound. In this tutorial, we will take up creating a balance slider which will allow you to shift the sound from one channel (right or left) to the other channel. The viewer on the site will be able to control the balance or the panning of the sound. Using ActionScripting with sound can be a very powerful tool in creating great effects and amazing interactivity.

Attaching the Sound
First we need to create the sound object. Import the desired sound into your Library. In this case, our sound is called "combo". Highlight the sound in your Library and choose Linkage from the Options menu of the Library. Select Export This Symbol and name the sound "combo".



Select the frame in the main timeline where the sound will begin, in this case, Frame 1. If you don't have the Actions window open, select from the menu Window > Actions. Under Frame Actions, Select Actions and then drag the "set variable" action from the toolbox on the left to the Script window on the right. In the Parameters Panel, at the bottom of the Actions Window you will see a line for Variable and a line for Value. Enter "s" in the Variable box.

In the Toolbox list, on the left, select Objects and then choose Sound. Here we are assigning the variable "s" to the sound "combo". Drag "new sound" to the Value box in the Parameters Panel.

In the Toolbox list again, select Actions and then double click or drag the "evaluate" action to the Scripts window. Enter "s" in the Expression box in the Parameters Panel. So we just identified "combo" as the sound to which we would like to add an action. In the Toolbox list, select Objects again and drag "attachsound" to the Expression box in the Parameters Panel. In the argument for "attachsound", enter "combo".This allows us to attach the sound in the timeline. Again, under Actions in the Toolbox, double-click or drag the "evaluate" action to the Scripts Window and enter "s" in the Expression box.

To have the sound begin to play, select Sound again under Objects in the Toolbox and drag "start" to the Expression box in the Parameters Panel. When finished, the script should appear as follows:



Note that you can tell Flash to begin playing the sound from a particular point in the sound. For example if you have a sound that is 10 seconds in length, using the secondOffset command, you can tell the sound to begin playing not at the beginning of it but let's say at 5 seconds into the sound. You can also tell Flash to loop the sound as many times as desired, say 50 times. So using this example, the last line of the above code would look like this:

s.start([5, 50]);

The above is derived from the following syntax:
s.start([secondOffset, loop]);

Creating the Balance Slider
Now that we have attached the sound in the timeline, we would like it to pan the sound as we move a button left or right on the screen. First we have to create a movie clip of a button and then assign it some actions. Here we created a minimalist representation of a balance slider.

First, create a button and drag it to the Stage. With the button selected, convert it to a symbol by selecting from the menu Insert > Convert to Symbol. Select the movie clip behavior for the symbol.

Now we need to attach some actions to the symbol itself. Double-click on the movie clip to enter Edit mode. With the button selected, choose Window > Actions if that window is not open already. With the following code, we will give the drag property to the balance slider:



Now return to the main timeline by exiting edit mode. With the following commands, we will give the coordinates for the balance control. Select the movie clip on the Stage and again, enter these actions in the Script Window:



Now you should be able to export or test your movie.



Author's URL: Bluegelmedia.com
Thank you for voting.
Rate this Materials:
Bad 
1 2 3 4 5 Excellent
print this page subscribe to newsletter subscribe to rss

Internet & computing Flash is a vector-based moving graphics format created by Macromedia for the publication of animations on the World Wide Web. More Flash & Swish: Most Popular Materials | Fresh Materials | More Flash Tutorials at FlashPerfection.com

Add comments to "Balance Slider or Panning Effect"

Only registered users can write comment

No comments yet...