|
-
Fading In and Out
Sorry I keep asking so many questions, but how do you make a sound fade in or out? A code, and maybe even a screenshot, would be appreciated. Thanks,
-Fyce
-
Senior Member
Well the basic volume control command is
my_sound.setVolume(level);
where 'level' is a number from 0 to 100 and
'my_sound' is the sound object used to play the sound.....
so usage will depend on how your sound is incorporated in your movie and fading in and out is achieved by altering the 'level' variable say in a loop.
hope this helps
mike
-
my_sound?
 Originally Posted by indogo
'my_sound' is the sound object used to play the sound.....
Wait, so the 'my_sound' part is where we put the file name? Like, 'song.mp3', or something? What do we put in the 'my_sound' part?
-Fyce
-
Senior Member
Ok ..say for example you wanted to play a song in the same folder (streamed) you could use
mySound = new Sound(); //creates a new sound object
mySound.loadSound("song.mp3", true); //loads the file in streaming mode
mySound.start(); //plays it
so all control of the music is referenced by the 'mySound' part
eg mySound.stop(); would stop the music
'mySound' can be any name you choose and bear in mind flash 7 and later is case sensitive.
hope this helps....takes a little while to sink in
mike
-
Error
 Originally Posted by indogo
Ok ..say for example you wanted to play a song in the same folder (streamed) you could use
mySound = new Sound(); //creates a new sound object
mySound.loadSound("song.mp3", true); //loads the file in streaming mode
mySound.start(); //plays it
so all control of the music is referenced by the 'mySound' part
eg mySound.stop(); would stop the music
'mySound' can be any name you choose and bear in mind flash 7 and later is case sensitive.
hope this helps....takes a little while to sink in
mike
I tried the first code, and it pops up an error message saying:
"Line 1: expecting a , or )"
On the mySound = new Sound(); part, do I put a filename in between the (), such as /Music/song.mp3, or just the song.mp3 part, or what? If you could give me a screenshot, that would be awesome!
-Fyce
Last edited by Fyce; 08-13-2006 at 10:46 PM.
-
 Originally Posted by indogo
hope this helps....takes a little while to sink in
mike
Mike, that is the most succinct and clear explanation I've seen. Or maybe I am finally getting my head around Actionscript enough to grasp it. If I ever start my KM wiki, that paragraph go in page one of Audio. Thanks.
-
 Originally Posted by Fyce
I tried the first code, and it pops up an error message saying:
"Line 1: expecting a , or )"
Fyce,
I just cut and pasted Mike's code into the first frame of a blank movie. I saved it into a folder that contained an mp3 that I had renamed as "song.mp3" to go with the code. Then I ran it in a browser and after a moment heard the sweet voice of Doris Day. Try cutting and pasting just this code part:
Code:
mySound = new Sound(); //creates a new sound object
mySound.loadSound("song.mp3", true); //loads the file in streaming mode
mySound.start(); //plays it
It otta woik. (Or put the name of your mp3 within the quotes in line 2.)
-
up to my .as in code
Mike, that is the most succinct and clear explanation I've seen. Or maybe I am finally getting my head around Actionscript enough to grasp it.
I'd say both are correct Jim Lookin good Mike
-
Senior Member
mySound = new Sound();
just as is...check nothing extra has been picked up when copying...does happen..
and is the code where jim describes?..use the movie 'overview/actionscript displayed' to check...is the best place to look when using code.
This will also play other tunes as well as Doris Day....
mike
-
 Originally Posted by indogo
mySound = new Sound();
This will also play other tunes as well as Doris Day....
mike
For sure. The Andrews Sisters, too. Not to mention Ella...
-
Relaxing
 Originally Posted by Fyce
Sorry I keep asking so many questions, but how do you make a sound fade in or out? A code, and maybe even a screenshot, would be appreciated. Thanks,
-Fyce
To fade in our out, you could put this into a movieclip . Then change the volume to 0 or 100 and change vol = vol - 1; to vol = vol =1; as needed for fade n or fade out
onClipEvent(load){
mySound = new Sound(); //creates a new sound object
mySound.loadSound("3.mp3", true); //loads the file in streaming mode
mySound.start(); //plays it
var vol;
vol = 100;
volume = vol;
mySound.setVolume(vol);
}
onClipEvent(enterFrame){
vol = vol - 1;
mySound.setVolume(vol);
if (vol >= 99) {
vol = 99;
}
else if (vol <= 0) {
vol = 0;
}
}
Any programming language is at its best before it is implemented and used.
-
Senior Member
Nicely rounded off 
Actionscript in bite sized chunks...thats what we serve in the koolmoves restaurant..
We now have all the ingredients...we now gaze at the oven in antici...pation.
mike
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
|