Copy link to clipboard
Copied
Ok... so I am a newbie to flash pretty much. So forgive me in advance. I
am trying to loop a small sound file (wav file because I was told wav will loop seemlessly)...
in any case, got the actionscript (2.0) to work with one simple button that acts as a
start and pause... but yet, the file still doesnt loop.
Does anyone have an actionscript that accomplishes this that I can take a peek at? I HAVE to be missing something small.. its driving me nuts.
It just will not loop.
Thanks a ton.
Dann
Copy link to clipboard
Copied
Can you describe the details of steps you took to create this and include the code you are using?
Copy link to clipboard
Copied
Here's the code...
var snd:Sound = new Sound(); //Create a new sound object
var sndFile:String;
var sndPlaying:Boolean = true; //Status flag indicating whether the sound is playing or not
var sndFinished:Boolean = false; //Status flag indicating whether the sound has finished playing or not
var startVolume:Number; //Start value of sound volume
var autoStart:Boolean;
//Extract the sound file name from the calling object
if (this.sndfile != undefined) {
sndFile = this.sndfile;
}
else {
//Default setting is "songnamehere".mp3
sndFile = "pinknoise.mp3";
}
if(this.sndvol != undefined) {
startVolume = int(this.sndvol);
} else {
startVolume = 50;
}
if (this.sndautostart == 0) {
autoStart = true;
} else {
autoStart = false;
}
snd.loadSound(sndFile, true); //Load the specified sound file and start streaming
snd.setVolume(startVolume); //Set initial sound volume
if(autoStart != true) {
snd.stop();
sndPlaying = false;
sndFinished = true;
mcPlay._visible = true;
mcPause._visible = false;
} else {
sndPlaying = true;
sndFinished = false;
mcPlay._visible = false;
mcPause._visible = true;
}
stop();
snd.onSoundComplete = function() {
sndPlaying = false;
sndFinished = true;
mcPause._visible = false;
mcPlay._visible = true;
}
mcPlay.onRelease = function() {
if(sndPlaying != true) {
mcPause._visible = true;
mcPlay._visible = false;
if(sndFinished == true) {
//Start playing the sound from the beginning
snd.start(0,999999999999999999999);
} else {
//Start playing the sound only if it was previously paused
snd.start(0,999999999999999999999);
}
sndPlaying = true;
sndFinished = false;
}
}
mcPause.onRelease = function() {
//Pause sound playing
snd.stop();
sndPlaying = false;
mcPause._visible = false;
mcPlay._visible = true;
Copy link to clipboard
Copied
If you are streaming the sound, you cannot specify looping for it... per the help documents...
loops:
Number [optional] - A parameter that lets you specify the number of times the sound should play consecutively. This parameter is not available if the sound is a streaming sound.
Copy link to clipboard
Copied
I do not want to stream this file...
Copy link to clipboard
Copied
Then you need another plan because you do stream it...
snd.loadSound(sndFile, true); //Load the specified sound file and start streaming
Try changing that second parameter to false and see if it does what you hope.
Copy link to clipboard
Copied
hrmm yes i see that. LOL... told ya i m a newbie... though i see its not as simple as just changing it to FALSE instead of true... hrmm..
I do not want this file to start when they load the page.. just when they use the controls... so I am really trying to keep with the script..
Copy link to clipboard
Copied
In addition to changing that to false, you should probably tame that 99999999999999999999.... loops value to something more realistic--start small and test for when it doesn't work anymore. I'm don't think the function is geared to handle a number that size.
Copy link to clipboard
Copied
WOW! Yup.. the crazy 9s did it! I was trying for an infinite loop... thus the 9's,,,
i have it at 99999 and its loopin,....
nice work!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now