Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,287 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,296 people online right now. Registration is fast and FREE... Join Now!




Action script sound toggle

 
Reply to this topicStart new topic

Action script sound toggle

luke_nunn
post 2 Oct, 2008 - 07:07 AM
Post #1


New D.I.C Head

*
Joined: 2 Oct, 2008
Posts: 1

I've made a code to allow the turning on and off a sound object.

This is the code:
CODE
play_btn.onRelease = function(){
    mySong = new Sound();
    mySong.attachSound("song");
    mySong.start(0, 50);
    
}
stop_btn.onRelease = function() {
    stopAllSounds ();


My problem is that when the play button is pressed multiple times it over laps itself, so its playing the sound file over itself.

I want it to just start again when the sound button is pressed rather than overlapping.

Any ideas???

Any help would be greatly appreciated:) Thankyou:)
User is offlineProfile CardPM

Go to the top of the page

Kerplope
post 2 Oct, 2008 - 02:35 PM
Post #2


New D.I.C Head

Group Icon
Joined: 22 Sep, 2008
Posts: 6



Dream Kudos: 100
My Contributions


That's funny just last night I submitted a snippet to solve this exact problem, unfortunately it hasn't come through the tubes yet and it's also for actionscript 3. I'm not sure about how to code it in actionscript 2 but it should be something like a boolean variable that checks to see if the song is playing and an if statement that will execute only if the boolean is true.
User is offlineProfile CardPM

Go to the top of the page

BetaWar
post 2 Oct, 2008 - 06:03 PM
Post #3


#include <soul.h>

Group Icon
Joined: 7 Sep, 2006
Posts: 1,983



Thanked 78 times

Dream Kudos: 1175
My Contributions


Here is a basic script for playing a sound:

Creating the sound object:
CODE
var _soundURL = SOME URL;

var netsound:Sound = new Sound();
netsound.loadSound(_soundURL, false);
netsound.setVolume(100);

var playingSound = 0;
var cue_point = 0;


Play button code (NOTE - This also acts as the paused button code)
CODE
playButton.onRelease = function() {
    if(playingSound == 0){
//goto playing view
        playingSound = 1;
        netsound.start(cue_point);
    }
    else{
//goto paused/stopped view
        playingSound = 0;
        cue_point = netsound.position/1000;
        netsound.stop();
    }
}


Stop sound function:
CODE
function stopSound() {
    if(cue_point != 0){
        netsound.start(0);
        cue_point = 0;
        if(playingSound == 1){
            playingSound = 0;
            //Have the play button go to the paused/stopped view
        }
        netsound.stop();
    }
}


That is the basics behind it, NOTE - You don't want to create a new sound object each and everytime you are playing the sound over, otherwise it WILL have the sounds overlapping. Create a single sound object outside of the functions.

Hope that helps.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/22/08 01:00AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month