dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: onSoundComplete and setVolume problems

  1. #1
    Senior Member
    Join Date
    Aug 2000
    Posts
    103

    onSoundComplete and setVolume problems

    Hi all.
    I'm having some sound confusion.
    Firstly, when I set the volume of one sound to a specific value, it appears to change the volumes of all other sounds. For example, in the below code, playing the ocean sound sets the volume of the intro sound to 10. Also, when I use onSoundComplete, it doesn't work at all.

    Can anyone help?



    Code:
    function fPlaySound(ID){
    	switch(ID){
    		case "intro":
    			var sndIntro:Sound = new Sound();
    			sndIntro.attachSound("PBCS01");
    			sndIntro.setVolume(100);
    			sndIntro.start();
                            sndIntro.onSoundComplete = function(){
                                _root.fPlaySound("intro2");
                            }
    			break;
    			
    		case "intro2":
    			var sndIntro2:Sound = new Sound();
    			sndIntro2.attachSound("PBCS01");
    			sndIntro2.start();
    			break;
    
    		case "click":
    			var sndIntro3:Sound = new Sound();
    			sndIntro3.attachSound("CLICK");
    			sndIntro3.start();
    			break;
    			
    		case "ocean":
    			var sndIntro4:Sound = new Sound();
    			sndIntro4.attachSound("OCEAN");
    			sndIntro4.setVolume(10);
    			sndIntro4.start(0,999999);
    			break;
    	}
    }
    
    _root.fPlaySound("intro");
    _root.fPlaySound("ocean");

  2. #2
    Senior Member
    Join Date
    Sep 2000
    Location
    Pittsburgh
    Posts
    252
    Hi,

    try creating an empty clip for each sound object and attaching the sound object to each clip at instantiation something like:


    Code:
    case "intro":
    this.createEmptyMovieClip("introSound", this.getNextHighestDepth());
    var sndIntro:Sound = new Sound(introSound);
    sndIntro.attachSound("PBCS01");
    i think this might also solve your onComplete problem.

    so i think what your doing essentially by creating 2 new sound objects like
    var mysound1:Sound = new Sound();
    var mysound2:Sound = new Sound();
    is creating them both at the same _level, clip, object or _root, however you want to say it, so when you set the volume on the last one it's being globally set for them all.

    hope this helps some,
    Dunc

  3. #3
    Senior Member
    Join Date
    Aug 2000
    Posts
    103
    Thanks.
    This solves the volume setting problem, but the onSoundComplete still doesn't work at all....I'm baffled!

    Code:
    function fPlaySound(ID){
    	switch(ID){
    		case "intro":
                            this.createEmptyMovieClip("introSound", this.getNextHighestDepth());
    			var sndIntro:Sound = new Sound(introSound);
    			sndIntro.attachSound("PBCS01");
    			sndIntro.setVolume(100);
    			sndIntro.start();
                            sndIntro.onSoundComplete = function(){
                                _root.fPlaySound("intro2");
                            }
    			break;
    			
    		case "intro2":
                            this.createEmptyMovieClip("introSound2", this.getNextHighestDepth());
    
    			var sndIntro2:Sound = new Sound(introSound2);
    			sndIntro2.attachSound("PBCS01");
    			sndIntro2.start();
    			break;
    
    	}
    }
    
    fPlaySound("intro");
    Last edited by aragorn23; 02-11-2005 at 03:31 AM.

  4. #4
    Senior Member
    Join Date
    Sep 2000
    Location
    Pittsburgh
    Posts
    252
    ok, yea this is a little strange and i'm not sure exactly why the onSoundComplete won't fire when you create the sound within the switch statement. If you move the the variable declaration of sndIntro out of the switch statement it will fire. Not sure if it is a scope thing within the switch statement or what.

    dunc

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center