-
[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";
}
}
-
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.
-
Thanks DiamondDog! It works!
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|