What's Here?
- Members: 244,287
- Replies: 693,149
- Topics: 113,164
- Snippets: 3,863
- Tutorials: 935
- Total Online: 979
- Members: 67
- Guests: 912
|
This snippet will set up the code necessary to play/pause and stop a sound in actionscript 3.
|
Submitted By: Kerplope
|
|
Rating:
 
|
|
Views: 9,165 |
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
|
|
|
Be Social
Programming
Web Development
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|