Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-27-2006, 11:36 AM   #1
schmichael
Registered User
 
Join Date: Jun 2006
Posts: 4
Default Stopping sounds playing on top of each other

Hey there, cheers for reading my post. I have written a simple function that should check if a bunch of other sound objects are playing and then play the sound object it is targeted at when the other sounds have finished by triggering the function again. I am storing whether the other sounds are playing in boolean variables. For some reason my code isn't working and I can't for the life of me figure out why. If someone would have a look that woulde be excellent. Thanks!

Code:
function PlayNumber(no) {
    trace("Play Number Called");
    if (soundOn) {
        if (welcomePlaying) {
            trace("welcomePlaying");
            Welcome.onSoundComplete = function() {
                welcomePlaying = false;
                trace("welcome finished")
                PlayNumber(no);
            };
        } else if (fHPlaying) {
            trace("FHPlaying");
            FHStart.onSoundComplete = function() {
                fHPlaying = false;
                PlayNumber(no);
            };
        } else if (linePlaying) {
            trace("line PLaying");
            LineStart.onSoundComplete = function() {
                PlayNumber(no);
            };
        } else if (numberPlaying) {
            trace("number Playing");
            numbers[lastNumber].onSoundComplete = function() {
                PlayNumber(no);
            };
        } else {
            trace("nothing playing");
            numbers[no].start();
            numberPlaying = true;
            numbers[no].onSoundComplete = function() {
                numberPlaying = false;
            };
        }
    }
}

function playWelcome(){
    welcome.start()
    welcomePaying = true;
    welcome.onSoundFinished = function(){
        welcomePLaying = false;

    }
}
schmichael is offline   Reply With Quote
Old 06-27-2006, 02:11 PM   #2
hothousegraphix
Senior Member
 
Join Date: Jun 2006
Posts: 201
Default

Hey...Just set up one variable to test for activity and then pass it from function to function; i.e.
ActionScript Code:
// create test variable x=0; song1btn.onRelease = function(){     if (x==0){ //look at test variable, if equal to 0 exicute function          NowPlaying=title1;//dynamic display of song title          mp3Player.loadSound("yourTitleHere.mp3",true);          x=1//prevent all other playbtn's from exicuting//      } }
Then you'll need to reset that variable back to 0 once the sound has completed, either on it's own with the onSoundComplete action, and/or with the stop action...
ActionScript Code:
//sound allowed to complete on its own mp3Player.onSoundComplete = function () {     x=0;// reset test variable to allow all other sounds to play     NowPlaying = "Complete";// Display message } //sound stopped by user stopbtn.onRelease = function() {     if (x==1){         mp3Player.stop();// stop sound         x=0;// reset test variable to allow all other sounds to play         NowPlaying="STOPPED";// Display message     } }
Hope this helps.
hothousegraphix is offline   Reply With Quote
Old 06-27-2006, 02:19 PM   #3
schmichael
Registered User
 
Join Date: Jun 2006
Posts: 4
Default Thanks

Hi Hothouse, thanks for your reply, it would solve my problem but the thing is that I need to play the sound files in a certain order if more than one is triggerd while another is playing. The priority in which they should be played is the order in which they are listed from the top of the function going down. The thing is I need this function to be dynamic so it can adapt whatever sounds are triggered but always play the sounds in order of their priority.
Any suggestions gratefully received, thanks again
schmichael is offline   Reply With Quote
Old 06-28-2006, 03:39 PM   #4
hothousegraphix
Senior Member
 
Join Date: Jun 2006
Posts: 201
Default

Sorry for not getting back sooner.

I guess I'm not understanding your entire situation. What is your goal? What triggers your sounds? Is your sequesnce of sounds supposed to exicute simelteaeously or one after the other?

What parts of your code are functioning?

There seems to be a contradiction between your script and what you are stating you want.

Your script asks to check a number of conditions and if true you script actions to be performed (if this conditions is met, do this; but if not check another condition, and so on); but, in your statement you say you want to have a sound play if condition1 and condition 2 and contionn 3 are all met at the same time.

Could you clarify?
hothousegraphix is offline   Reply With Quote
Old 06-28-2006, 03:53 PM   #5
schmichael
Registered User
 
Join Date: Jun 2006
Posts: 4
Default cheers

Hi there, thanks for getting back to me again Hothouse Sorry if I didnt explain myself properly.

The sounds are triggered by XML messages from a socket connection. That part of things works fine. I need to make the flash file work so that if another message is received that triggers another sound while one is playing already, the next triggered sound will play after the current one has finished, that bit seems OK; the problem is that if say, 3 sounds are triggered to play I need them to play in a certain order e.g. if the LineStart sound, the welcome sound and a number are all triggered, I need them to play in the order Welcome, LineStart then number. My code is
written in the order that the files should play so it checks if the welcome sound is playing, if it is it waits until the sound has finished and then triggers the function again, this time the welcome sound has finished so the second condition is checked and the cycle goes on.

I hope this makes sense, thanks for your help again!

Last edited by schmichael; 06-28-2006 at 03:57 PM.
schmichael is offline   Reply With Quote
Old 06-29-2006, 12:52 AM   #6
hothousegraphix
Senior Member
 
Join Date: Jun 2006
Posts: 201
Default

OK, a few things I see, in the script you posted, your "if" statments don't actually state conditions. You want to test for the presence of something.
For instance, when you exicute your welcomePlaying track, you established a variable you can test for: i.e.
ActionScript Code:
welcomePlaying = true
but your not actually testing for it:
ActionScript Code:
//your code function PlayNumber(no) {     trace("Play Number Called");     if (soundOn) {  //       if (welcomePlaying) { - this line sould look like below           if (welcomePlaying == true) { // <-- New line             trace("welcomePlaying");             Welcome.onSoundComplete = function() {                 welcomePlaying = false;                 trace("welcome finished")                 PlayNumber(no);             }; // and so on // you also need to watch your script as AS 2 is case sensetive
Also need to look at "playWelcome" function. I could be wrong but I don't believe onSoundFinished is a method you can exicute, sould be onSoundComplete.

Also to test for a state with multipal conditions your "if" statement should look something like this:
ActionScript Code:
if(audioClip1==true && audioClip2==true && audioClip3==true){ // will only exicute if all 3 conditions are met at the same time     do something here }

I hope this helps.
hothousegraphix is offline   Reply With Quote
Old 06-29-2006, 08:18 AM   #7
schmichael
Registered User
 
Join Date: Jun 2006
Posts: 4
Default

Thanks for your continued help HotHouse. As far as I know you can test to see if a boolean variable is true in that way, if you run this code:
Code:
var myBoo:Boolean = true;
if (myBoo) {
	trace("it's true");
}
It will trace if myBoo is true and won't if it isn't.

I'm not quite sure where I got the onSoundFinished property from I think I must have made it up, so I'lll change that back to onSoundComplete.

As far as I am aware, if you test a bunch of conditions using if/else statements the first one that is met will execute, for example, if you run the code below:
Code:
function testNum(number:Number) {
	if (number>6) {
		trace("more than 6");
	} else if (number<10) {
		trace("less than 10");
	} else {
		trace("met no conditions");
	}
}
If the number is 5 the 2nd condition will be met, but if the number is 7 (which meets the 1st and 2nd conditions) the first condition will execute.

I hope this helps explain the code more clearly.
Cheers
Schm
schmichael is offline   Reply With Quote
Old 05-14-2012, 08:45 AM   #8
IncomingVirus
Registered User
 
Join Date: May 2012
Posts: 3
Default

Hi, I am new to this forum. I am busy building a flash site for a band but I am very new to sound in flash. I am using actionscript 2.

What I want to do with their songs is when you click on the button the song starts playing (That part I can do), what I am having trouble with is if you click the button to play "song 1" (it starts playing) and then click the button to play "song 2", I want "song 1" to stop automatically. I don't want the user to have to click a stop button.

I put the song into the song button's timeline as I am not very good with the coding in flash.

Any help will be much appreciated.
IncomingVirus is offline   Reply With Quote
Old 05-14-2012, 10:29 AM   #9
Prid
Prid - Outing
 
Prid's Avatar
 
Join Date: Oct 2009
Location: Halden, Norway
Posts: 1,191
Send a message via MSN to Prid Send a message via Skype™ to Prid
Default

Please don't double-post
__________________
I have returned, and am now 18
Prid is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
playing and stopping sound ginger20 Flash 8 General Questions 0 05-24-2006 09:45 AM
stopping flv from playing until certain % has downloaded chelnov63 ActionScript 2.0 11 07-23-2005 04:28 AM
Help! Stopping Specific Sounds theinfiltrator ActionScript 2.0 1 05-29-2005 08:33 AM
Playing Sounds in an Array? liquidrain ActionScript 2.0 3 11-12-2004 10:04 PM
a problem with stopping sounds that were loaded from another swf nam ActionScript 2.0 2 05-28-2004 12:37 PM


All times are GMT. The time now is 02:18 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.