A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [CS3] AS3 - Make sound loop

  1. #1
    Junior Member
    Join Date
    Jun 2008
    Posts
    4

    [CS3] AS3 - Make sound loop

    Hey I'm using this code to play/stop a sound in my flash movie, but I can't figure out how to make it loop. What do I need to do?

    Code:
    import flash.media.Sound;
    import flash.media.SoundChannel;
    
    status.text = "Chimes Off";
    
    playButton.addEventListener(MouseEvent.MOUSE_DOWN, playChimes);
    
    var chimesSound:SoundChannel; 
    
    function playChimes(e:MouseEvent):void{
    	if(status.text == "Chimes Off"){
    		var chimes:Chimes = new Chimes();
    		chimesSound = chimes.play();
    		status.text = "Chimes On";
    	}else{
    		chimesSound.stop();   
        	status.text = "Chimes Off";
    	}
    }

  2. #2
    Senior Member
    Join Date
    Oct 2007
    Location
    Leeds, UK
    Posts
    118
    Code:
    import flash.media.Sound;
    import flash.media.SoundChannel;
    
    status.text = "Chimes Off";
    
    playButton.addEventListener(MouseEvent.MOUSE_DOWN, playChimes);
    
    var chimesSound:SoundChannel; 
    
    function playChimes(e:MouseEvent):void{
    	if(status.text == "Chimes Off"){
    		var chimes:Chimes = new Chimes();
    		chimesSound = chimes.play(0,int.MAX_VALUE);
    		status.text = "Chimes On";
    	}else{
    		chimesSound.stop();   
        	status.text = "Chimes Off";
    	}
    }
    That play method takes three parameters.
    The first one is how far in you want the sound file to start (in milliseconds), and the second one is
    how many times you want the sound file to loop. (int.MAX_VALUE gives us an endless loop for all practicial purposes).
    If you wanted to apply a sound transform, you'd give that as the third parameter.

  3. #3
    Junior Member
    Join Date
    Jun 2008
    Posts
    4
    Thanks DiamondDog! It works!

  4. #4
    Member
    Join Date
    Sep 2008
    Posts
    80
    works like a charm thanks!!!

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