Cuyamaca Collegeskip to content
Apply & Enroll
Departments
Help for Students
Find People
Online Services
Campus Information
Student Activities
Graphic Design: 

 
Flash Distraction
of the Week

About TED

GCCCD Blackboard

GD 222
Home
Syllabus
Schedule
News
Labs
Videos
Flash Resources
Web Dev Resources

 

GD 222 Flash Web Animation - Spring, 2009
Online Course
http://www.cuyamaca.edu/jeff.sale/gd222/

Flash Example
Button State Sounds
Baro

This is a simple example of how to use ActionScript 2.0 to cause a sound to play for each of the four events associated with a Button: rollover, mouse button press, mouse button release, and rollout.

Here are the steps to follow to create button sounds for each state.

Step 1: Import your sounds to the Library

Step 2: Right-click each sound and select Linkage from the popup menu

Step 3: Check the Export for ActionScript checkbox and the Export in first frame checkbox

Step 4: Enter a short name for each sound in the Identifier box. This name will be used in your ActionScript for the attachSound command. Click OK.

Step 5: Create your button on the Stage

Step 6: Add a new Layer, select Frame 1 in the Timeline and enter the following script in the ActionScript panel:

/*This script causes a sound to be played for each
of the four possible states of button events: rollover,
mouse button press, mouse button release, and rollout
*/

//Define sound variables to be referenced by the play_btn
var over_sound:Sound = new Sound();
var down_sound:Sound = new Sound();
var up_sound:Sound = new Sound();
var out_sound:Sound = new Sound();

//Attach your sounds to each button state
over_sound.attachSound("b_wop");
down_sound.attachSound("boing");
up_sound.attachSound("spring");
out_sound.attachSound("twingy");

//Define the function to be called on a mouse rollover event
play_btn.onRollOver = function() {
over_sound.start();
};

//Define the function to be called on mouse button press event
play_btn.onPress = function() {
down_sound.start();
};

//Define the function to be called on mouse button release event
play_btn.onRelease = function() {
up_sound.start();
};

p//Define the function to be called on rollout event
ay_btn.onRollOut = function() {
out_sound.start();
};

Step 7: Test your movie. It should behave similar to the example above.

Download the file used in this example.

Download a Flash 8 format file for this example.


Jeff Sale

E-mail: jeff.sale (at) gcccd.edu
Phone: 619-660-4000
Fax: 619-660-4399
Graphic Design, Cuyamaca College
You may also reach me at jsale37 (at) gmail.com

 

 

Page footer information

12 Nov 2009 13:54:47 -0800