What's Here?
- Members: 131,932
- Replies: 470,201
- Topics: 72,877
- Snippets: 2,538
- Tutorials: 664
- Total Online: 1,764
- Members: 74
- Guests: 1,690
Who's Online?
|
This snippet will set up the code necessary to play/pause and stop a sound in actionscript 3.
|
Submitted By: Kerplope
|
|
Rating:

|
|
Views: 383 |
Language: ActionScript
|
|
Last Modified: October 8, 2008 |
|
Instructions: You will need to create two buttons one that will be your play/pause button and another that that will be your stop button. Also be sure to define the path of the sound file. |
Snippet
//number that is redefined when the pause button is hit
var pausePoint:Number = 0.00;
//a true or false value that is used to check whether the sound is currently playing
var isPlaying:Boolean;
//think of the soundchannel as a speaker system and the sound as an mp3 player
var soundChannel:SoundChannel = new SoundChannel();
var sound:Sound = new Sound(new URLRequest("SOUNDPATH/EVENDEEPER/SOUND.mp3"));
//you should set the xstop and xplay values to match the instance names of your stop button and play/pause buttons
xstop.addEventListener(MouseEvent.CLICK, clickStop);
xplay.addEventListener(MouseEvent.CLICK, clickPlayPause);
soundChannel = sound.play();
isPlaying = true;
function clickPlayPause(evt:MouseEvent) {
if (isPlaying) {
pausePoint = soundChannel.position;
soundChannel.stop();
isPlaying = false;
} else if (!isPlaying) {
soundChannel = sound.play(pausePoint);
isPlaying = true;
}
}
function clickStop(evt:MouseEvent) {
if (isPlaying) {
soundChannel.stop();
isPlaying = false;
}
pausePoint = 0.00;
}
Copy & Paste
|
|
|
Programming
Web Development
Reference Sheets
Bye Bye Ads
Free DIC T-Shirt
Related Sites
Monthly Drawing
Partners
Top Contributors
Top 10 Kudos This Month
|