A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [RESOLVED] Stopping a sound when new sound starts.

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    7

    resolved [RESOLVED] Stopping a sound when new sound starts.

    I'm making a little interactive ad. It has 4 draggable song titles, that when dropped on a target, starts the song. I'm trying to figure out how to stop the song that's playing when a new song is started. Here's my code:

    Code:
    package {
    	import flash.display.*;
    	import flash.events.*;
    	import flash.media.Sound;
    	import flash.net.URLRequest;
    	
    	public class Deftones extends MovieClip{
    	
    	function Deftones() {
    	
    	swerve1.addEventListener(MouseEvent.MOUSE_DOWN, dragStartS);
        swerve1.addEventListener(MouseEvent.MOUSE_UP, dragEndS);
    	polt1.addEventListener(MouseEvent.MOUSE_DOWN, dragStartS);
        polt1.addEventListener(MouseEvent.MOUSE_UP, dragEndS);
    	rd1.addEventListener(MouseEvent.MOUSE_DOWN, dragStartS);
        rd1.addEventListener(MouseEvent.MOUSE_UP, dragEndS);
    	gauze1.addEventListener(MouseEvent.MOUSE_DOWN, dragStartS);
        gauze1.addEventListener(MouseEvent.MOUSE_UP, dragEndS);
    	var sound1:Sound= new Sound();
    	var sound2:Sound= new Sound();
    	var sound3:Sound= new Sound();
    	var sound4:Sound= new Sound();
    	sound1.load(new URLRequest("music/Swerve_City.mp3"));
    	sound2.load(new URLRequest("music/Poltergeist.mp3"));
    	sound3.load(new URLRequest("music/Romantic_Dreams.mp3"));
    	sound4.load(new URLRequest("music/Gauze.mp3"));
    
        function dragStartS(e:MouseEvent){
        	e.currentTarget.startDrag();
        }
        function dragEndS(e:MouseEvent){
        	e.currentTarget.stopDrag();
    		if (swerve1.hitTestObject(speaker1)){
    				sound1.play(0);
    		}
    		else if (polt1.hitTestObject(speaker1)){
    				sound2.play(0);
    		}
    		else if (rd1.hitTestObject(speaker1)){
    				sound3.play(0);
    		}
    		else if (gauze1.hitTestObject(speaker1)){
    				sound4.play(0);
    		}
        }
    	
    	}
    }
    }
    Any help would be very much appreciated.

  2. #2
    Junior Member
    Join Date
    Oct 2012
    Posts
    7
    Figured this out. *SOLVED*

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