Be a Supporter!
Rammer
Rammer
  • Member since: Jun. 8, 2003
  • Offline.
Forum Stats
Member
Level 33
Programmer
Response to AS: Sound Oct. 1st, 2005 @ 06:05 PM Reply

At 10/1/05 06:04 PM, 2k_rammerizkool wrote: you forgot loadSound (:

it loads a sound dynamically from a URL. works kinda like this

loadSound("http://rammerzworld.com/sound.m
p3", true)

the "true" in there sets it to stream the sound, i think.

oops, sorry about double-post, but i forgot to mention that this only works with mp3 sounds \:


snyggys

Kadachi
Kadachi
  • Member since: Sep. 5, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Sound Oct. 31st, 2005 @ 11:39 AM Reply

nice thank you really much

IWantSomeCookies
IWantSomeCookies
  • Member since: Aug. 20, 2004
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to AS: Sound Oct. 31st, 2005 @ 12:10 PM Reply

Awesome Denver. Lol.

Thanks for another tut! :)


"Actually, the server timed out trying to remove all your posts..."
-TomFulp

Nemo
Nemo
  • Member since: Jun. 13, 2003
  • Offline.
Forum Stats
Member
Level 34
Game Developer
Response to AS: Sound Nov. 4th, 2005 @ 05:42 PM Reply

Is there any way to use Actionscripted sounds without having to "export in first frame?" I've got a game I'm making and want to use all Actionscripted sounds, but if I do that then I have to wait for the sounds to load before my preloader. Does anyone know any way to alleviate the problem?


BBS Signature
Nemo
Nemo
  • Member since: Jun. 13, 2003
  • Offline.
Forum Stats
Member
Level 34
Game Developer
Response to AS: Sound Nov. 4th, 2005 @ 06:39 PM Reply

Bump!


BBS Signature
Nemo
Nemo
  • Member since: Jun. 13, 2003
  • Offline.
Forum Stats
Member
Level 34
Game Developer
Response to AS: Sound Nov. 11th, 2005 @ 02:42 PM Reply

At 11/4/05 05:42 PM, Atomic_Sponge wrote: Is there any way to use Actionscripted sounds without having to "export in first frame?" I've got a game I'm making and want to use all Actionscripted sounds, but if I do that then I have to wait for the sounds to load before my preloader. Does anyone know any way to alleviate the problem?

If anyone is having a problem like this, I have finally found a solution. Just make a movie clip that is at least 2 frames long. In the first frame put a stop(); action and in the second frame put all of your sounds you want to export and set to Start or Event (make new keyframe for each of them). Then, take that movie clip and put it somewhere in the beginning of your movie, after your preloader and before you make any new sound objects. Now, any sound that is in the movie clip does not have to be set to "Export in First Frame" to be able to use. I can't believe this took me that long to figure out...


BBS Signature
Gotzen-Dammerung
Gotzen-Dammerung
  • Member since: Nov. 19, 2004
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Sound Nov. 26th, 2005 @ 05:12 PM Reply

This is going to sound stupid:

What's an MC?

Dislexsick
Dislexsick
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to AS: Sound Dec. 28th, 2005 @ 10:04 PM Reply

At 11/26/05 05:12 PM, Gotzen-Dammerung wrote: This is going to sound stupid:

What's an MC?

Movieclip

Neashir
Neashir
  • Member since: Aug. 8, 2005
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to AS: Sound Dec. 28th, 2005 @ 10:07 PM Reply

At 12/28/05 10:04 PM, Dislexsick wrote: Movieclip

Thank you for answering a month old question, I thought the world was going to end if it went unanswered. Or did you even look at when the last post was?

Goldencat
Goldencat
  • Member since: Aug. 2, 2005
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to AS: Sound Feb. 15th, 2006 @ 12:26 AM Reply

How do you change the "instance name" of it when you're looping inside movie clips. I just renamed my movie clip "Sound01" and that doesn't work.

Goldencat
Goldencat
  • Member since: Aug. 2, 2005
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to AS: Sound Feb. 15th, 2006 @ 12:45 AM Reply

I've figured out how to name the instance, but my flash still doesn't loop properly. I followed every instruction on the second part about looping in Movie Clips and as soon as my regular timeline is finished, the loop will just repeat over itself and so on until it gets hard to hear because of all the noise, what should I do?

LeechmasterB
LeechmasterB
  • Member since: Apr. 1, 2005
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Sound Mar. 1st, 2006 @ 10:54 AM Reply

What i posted is an as 2.0 class which you can use with flash mx or later. You can reuse it for any games and also add more functions and additional functionality. It is very simple and easy to understand if you look at it carefully.

[code]

class SoundManager {
public var sounds:Array;
// An array that holds all game sounds
public var music:Array;
// An array that holds the game music
public var musicStopped:Boolean;
// is the music stoped?
public var currentMusic:Number;
// song playing right now
public var numberofSounds:Number;
// total number of sounds
public var numberofSongs:Number;
// total number of sounds
public var fadeInterval;
// a var for the fade interval
public function SoundManager() {
currentMusic = -1;
// -1 is no selected song
musicStopped = true;
// music wont play at load
numberofSounds = 8;
// how many sounds are there?
numberofSongs = 2;
// how many songs?
sounds = new Array(numberofSounds);
for (var i = 0; i<sounds.length; i++) {
sounds[i] = new Sound();
sounds[i].attachSound("demoSound"+i+".mp3"
);
// Attach all sounds to sound objects and put them into the sounds array
// The sounds need to have a linkage identifier called demoSound"#NUMBER".mp3
}
/*********************************/
music = new Array(numberofSongs);
for (var i = 0; i<music.length; i++) {
music[i] = new Sound();
music[i].attachSound("music"+i+".mp3");
// Attach all songs to sound objects and put them into the sounds array
// The songs need to have a linkage identifier called music"#NUMBER".mp3
}
_global.soundManager = this;
// a global reference to this class
}
public function killAll():Void {
for (var i = 0; i<sounds.length; i++) {
stopSound(i);
}
/*********************************/
stopMusic();
// kills all sounds and turns the music off
}
public function fadeIn(duration:Number, num:Number):Void {
// start fading in
clearInterval(_global.soundManager.fadeInt
erval);
/**************/
playMusic(num);
music[currentMusic].setVolume(0);
fadeInterval = setInterval(_global.soundManager.fade(0), 10*duration);
}
public function fadeOut(duration:Number):Void {
// start fading out
clearInterval(_global.soundManager.fadeInt
erval);
/**************/
fadeInterval = setInterval(_global.soundManager.fade(1), 10*duration);
}
public function fade(num:Number):Void {
// this gets handled by the soundManager it will fade a song
var pan:Number = music[currentMusic].getVolume();
if (num) {
if (pan == 0) {
stopMusic();
clearInterval(_global.soundManager.fadeInt
erval);
} else {
music[currentMusic].setVolume(pan-1);
}
} else {
if (pan == 100) {
clearInterval(_global.soundManager.fadeInt
erval);
} else {
music[currentMusic].setVolume(pan+1);
}
}
}
public function playMusic(num:Number):Void {
// if _global.soundON is set true
//(a global variable storing weather sound is on or of)
// play the song passed with the number
if (_global.soundON) {
if (currentMusic != num || musicStopped) {
stopMusic();
//trace("start music: "+num);
music[num].start(0, 99999);
currentMusic = num;
musicStopped = false;
}
}
}
public function stopMusic():Void {
// stops the song currently playing
music[currentMusic].stop();
musicStopped = true;
}
public function playSound(num:Number):Void {
// plays a sound
if (_global.soundON) {
sounds[num].start();
}
}
public function stopSound(num:Number):Void {
// stops a sound
sounds[num].stop();
}
}

[/code]

I added the functions to fade sound....

The code above needs to be in a file called SoundManager.as

In the game you can use it like this after you set the number of songs and sounds in teh as file correctly and have the correct named files in your fla with the linkage identifier set:

var soundman = new SoundManager();
// creates a new instance of the soundmanager, you need only one, Its a singleton class.

If you for example have 8 sounds and 2 songs:

soundman.playMusic(1);

Plays song number two 9999 times or until stoped or another song is launched. And soundman.stopMusic(); will stop it again.

soundman.playSound(3);

Plays sound number two once but it can also be stoped early with:

soundman.stopSound(3);

To fade a sound in over a time of 20 seconds you call this:

soundman.fadeIn(20, 1);

or to fade it out again:

soundman.fadeOut(20);

Nobody is forcing you to use the comfort of oop and recycling code without ever having to worry about it again. ;) I did not test this but it should work and if it does not work then the problem is that the class properties cannot be accessed from within the fade(num:Number) function because its called by an interval. So you need to fully reference every function call and variable to the soundmanager in that function if it should not work and everything else is set up right.

greets

DarkScythes
DarkScythes
  • Member since: May. 20, 2005
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to AS: Sound Mar. 1st, 2006 @ 11:13 AM Reply

Nice tutorial. I have been wondering how to do a lot of that with AS for a while.

LeechmasterB
LeechmasterB
  • Member since: Apr. 1, 2005
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Sound Mar. 1st, 2006 @ 04:35 PM Reply

I did not test the code above so here is the working version with bug fixes:
(i also added an example fla ... see below)
[code]
class SoundManager {
public var sounds:Array;
// An array that holds all game sounds
public var music:Array;
// An array that holds the game music
public var musicStopped:Boolean;
// is the music stoped?
public var currentMusic:Number;
// song playing right now
public var numberofSounds:Number;
// total number of sounds
public var numberofSongs:Number;
// total number of sounds
public var fadeInterval;
// a var for the fade interval
public var fadeNum:Number;
public function SoundManager() {
currentMusic = 0;
// -1 is no selected song
musicStopped = true;
// music wont play at load
numberofSounds = 8;
// how many sounds are there?
numberofSongs = 2;
// how many songs?
sounds = new Array(numberofSounds);
for (var i = 0; i<sounds.length; i++) {
sounds[i] = new Sound();
sounds[i].attachSound("demoSound"+i+".mp3"
);
// Attach all sounds to sound objects and put them into the sounds array
// The sounds need to have a linkage identifier called demoSound"#NUMBER".mp3
}
/*********************************/
music = new Array(numberofSongs);
for (var i = 0; i<music.length; i++) {
music[i] = new Sound();
music[i].attachSound("music"+i+".mp3");
// Attach all songs to sound objects and put them into the sounds array
// The songs need to have a linkage identifier called music"#NUMBER".mp3
}
_global.soundManager = this;
// a global reference to this class
}
public function killAll():Void {
for (var i = 0; i<sounds.length; i++) {
stopSound(i);
}
/*********************************/
stopMusic();
// kills all sounds and turns the music off
}
public function fadeIn(duration:Number, num:Number):Void {
// start fading in
clearInterval(_global.soundManager.fadeInt
erval);
/**************/
playMusic(num);
music[num].setVolume(1);
fadeNum = 0;
fadeInterval = setInterval(_global.soundManager.fade, 10*duration);
}
public function fadeOut(duration:Number):Void {
// start fading out
clearInterval(_global.soundManager.fadeInt
erval);
/**************/
fadeNum = 1;
fadeInterval = setInterval(_global.soundManager.fade, 10*duration);
}
public function fade():Void {
var num = _global.soundManager.fadeNum;
// this gets handled by the soundManager it will fade a song
var pan:Number = _global.soundManager.music[_global.soundMa
nager.currentMusic].getVolume();
if (num) {
if (pan == 0) {
_global.soundManager.stopMusic();
clearInterval(_global.soundManager.fadeInt
erval);
} else {
_global.soundManager.music[_global.soundMa
nager.currentMusic].setVolume(pan-1);
}
} else {
if (pan == _global.MaxVolume) {
clearInterval(_global.soundManager.fadeInt
erval);
} else {
_global.soundManager.music[_global.soundMa
nager.currentMusic].setVolume(pan+1);
}
}
}
public function playMusic(num:Number):Void {
// if _global.soundON is set true
//(a global variable storing weather sound is on or of)
// play the song passed with the number
if (_global.soundON) {
if (currentMusic != num || musicStopped) {
stopMusic();
//trace("start music: "+num);
music[num].setVolume(_global.MaxVolume);
music[num].start(0, 99999);
currentMusic = num;
musicStopped = false;
}
}
}
public function stopMusic():Void {
// stops the song currently playing
music[currentMusic].stop();
musicStopped = true;
}
public function playSound(num:Number):Void {
// plays a sound
if (_global.soundON) {
sounds[num].setVolume(_global.MaxVolume);
sounds[num].start();
}
}
public function stopSound(num:Number):Void {
// stops a sound
sounds[num].stop();
}
}

[/code]

And to test the example go here:

http://www.dubhdroia..ch/test/Example.html

Here is the source to the example:

http://www.dubhdroia..est/SoundManager.zip

LeechmasterB
LeechmasterB
  • Member since: Apr. 1, 2005
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Sound Mar. 1st, 2006 @ 11:13 PM Reply

Now it has also a pause feature for the music!

[code]

class SoundManager {
public var sounds:Array;
// An array that holds all game sounds
public var music:Array;
// An array that holds the game music
public var musicStopped:Boolean;
// is the music stoped?
public var currentMusic:Number;
// song playing right now
public var numberofSounds:Number;
// total number of sounds
public var numberofSongs:Number;
// total number of sounds
public var fadeInterval;
// a var for the fade interval
public var fadeNum:Number;
public var posBackup:Number;
// needed for pausing
public var musicPaused:Boolean;
public function SoundManager() {
currentMusic = 0;
// -1 is no selected song
musicStopped = true;
// music wont play at load
numberofSounds = 8;
// how many sounds are there?
numberofSongs = 2;
// how many songs?
musicPaused = false;
sounds = new Array(numberofSounds);
for (var i = 0; i<sounds.length; i++) {
sounds[i] = new Sound();
sounds[i].attachSound("demoSound"+i+".mp3"
);
// Attach all sounds to sound objects and put them into the sounds array
// The sounds need to have a linkage identifier called demoSound"#NUMBER".mp3
}
/*********************************/
music = new Array(numberofSongs);
for (var i = 0; i<music.length; i++) {
music[i] = new Sound();
music[i].attachSound("music"+i+".mp3");
// Attach all songs to sound objects and put them into the sounds array
// The songs need to have a linkage identifier called music"#NUMBER".mp3
}
_global.soundManager = this;
// a global reference to this class
}
public function killAll():Void {
for (var i = 0; i<sounds.length; i++) {
stopSound(i);
}
/*********************************/
stopMusic();
// kills all sounds and turns the music off
}
public function fadeIn(duration:Number, num:Number):Void {
// start fading in
clearInterval(_global.soundManager.fadeInt
erval);
/**************/
playMusic(num);
music[num].setVolume(1);
fadeNum = 0;
fadeInterval = setInterval(_global.soundManager.fade, 10*duration);
}
public function fadeOut(duration:Number):Void {
// start fading out
clearInterval(_global.soundManager.fadeInt
erval);
/**************/
fadeNum = 1;
fadeInterval = setInterval(_global.soundManager.fade, 10*duration);
}
public function fade():Void {
var num = _global.soundManager.fadeNum;
// this gets handled by the soundManager it will fade a song
var pan:Number = _global.soundManager.music[_global.soundMa
nager.currentMusic].getVolume();
if (num) {
if (pan == 0) {
_global.soundManager.stopMusic();
clearInterval(_global.soundManager.fadeInt
erval);
} else {
_global.soundManager.music[_global.soundMa
nager.currentMusic].setVolume(pan-1);
}
} else {
if (pan == _global.MaxVolume) {
clearInterval(_global.soundManager.fadeInt
erval);
} else {
_global.soundManager.music[_global.soundMa
nager.currentMusic].setVolume(pan+1);
}
}
}
public function pauseMusic():Void {
if (musicPaused) {
playMusic(currentMusic);
musicPaused = false;
} else {
posBackup = music[currentMusic].position;
stopMusic();
musicPaused = true;
}
}
public function playMusic(num:Number):Void {
// if _global.soundON is set true
//(a global variable storing weather sound is on or of)
// play the song passed with the number
if (_global.soundON) {
if (currentMusic != num || musicStopped || musicPaused) {
stopMusic();
//trace("start music: "+num);
music[num].setVolume(_global.MaxVolume);
if (posBackup != 0 && currentMusic == num) {
trace("unpausing");

music[num].start(Math.round(posBackup/1000
), 99999);
} else {
trace("normal playing");
music[num].start(0, 99999);
}
posBackup = 0;
musicPaused = false;
currentMusic = num;
musicStopped = false;
}
}
}
public function stopMusic():Void {
// stops the song currently playing
music[currentMusic].stop();
musicStopped = true;
}
public function playSound(num:Number):Void {
// plays a sound
if (_global.soundON) {
sounds[num].setVolume(_global.MaxVolume);
sounds[num].start();
}
}
public function stopSound(num:Number):Void {
// stops a sound
sounds[num].stop();
}
}

[/code]

And to test the example go here:

http://www.dubhdroia..ch/test/Example.html

Here is the source to the example:

http://www.dubhdroia..est/SoundManager.zip

LeechmasterB
LeechmasterB
  • Member since: Apr. 1, 2005
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Sound Mar. 2nd, 2006 @ 04:24 PM Reply

Okay i made two examples, one for games and one for movies.

Example one using the manager with buttons:

http://www.dubhdroia..t/Example1Games.html

Example two using it with frames:

http://www.dubhdroia../Example2Movies.html

The source with the as and fla files:

http://www.dubhdroia..est/SoundManager.zip

greets and enjoy

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to AS: Sound Mar. 2nd, 2006 @ 04:25 PM Reply

At 3/2/06 04:24 PM, LeechmasterB wrote: Okay i made two examples, one for games and one for movies.

Thanks for these, I haven't had a reason to try them out yet, but your work is certainly appreciated.


- - Flash - Music - Images - -

BBS Signature
LeechmasterB
LeechmasterB
  • Member since: Apr. 1, 2005
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Sound Mar. 2nd, 2006 @ 04:28 PM Reply

No problem your welcome! :)

LeechmasterB
LeechmasterB
  • Member since: Apr. 1, 2005
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Sound Mar. 4th, 2006 @ 02:04 AM Reply

Sorry, had to delete the zip and example files because people dont want my shit here.. the code is still there anyways.

blingblingx1
blingblingx1
  • Member since: Mar. 22, 2006
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Sound Mar. 29th, 2006 @ 03:36 PM Reply

how do i make a sound play when i click the mouse

var bc=1000; //bulletcount
_root.onMouseDown=function(){
bc++;
if(bc>1100){ bc=1000; } //Reset bulletcount
duplicateMovieClip("bullet", "b"+bc, bc); //Create dupe bullet
}

thats in the frame the sounds name is "uhhh"

please help

gotflash
gotflash
  • Member since: Aug. 8, 2005
  • Offline.
Forum Stats
Member
Level 21
Blank Slate
Response to AS: Sound Jun. 23rd, 2006 @ 11:10 PM Reply

At 3/29/06 03:36 PM, blingblingx1 wrote: how do i make a sound play when i click the mouse

i too need help with this :(

Kool-Aid
Kool-Aid
  • Member since: Aug. 27, 2005
  • Offline.
Forum Stats
Member
Level 22
Game Developer
Response to AS: Sound Jun. 29th, 2006 @ 12:59 AM Reply

wow thanks, i was looking for this tutorial

Dragon909
Dragon909
  • Member since: Dec. 16, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Sound Jul. 15th, 2006 @ 06:15 AM Reply

How do I get 3 different sound buttons to work, so if you press for 1, it plays background music 1, press for 2, it plays background music 2 etc

23450
23450
  • Member since: May. 28, 2003
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to AS: Sound Jul. 29th, 2006 @ 02:54 AM Reply

bah. i cant believe im having this problem. ok. This code works 100% right:

_root.foot = new Sound(this);
_root.foot.attachSound("FootStep");

and starting it at a different time. Now, what isn't working is, if i do this:

_root.laserSound = new Sound(this);
_root.laserSound.attachSound("laser");
_root.foot = new Sound(this);
_root.foot.attachSound("FootStep");

suddenly, the laser sound works fine, but the foot sound does not work at all. If i take out the two laser ligns again, its works 100% again. Anyone know what the problem could be?


BBS Signature
23450
23450
  • Member since: May. 28, 2003
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to AS: Sound Jul. 29th, 2006 @ 03:01 AM Reply

ok. i figured something out. The footstep sound is only going when the laser sound is going. it cant be started without the laser sound being started, and when the laser sound ends, the foot sound ends. even though im saying _root.laser.stop(), it stops both. any ideas?


BBS Signature
Gummi-Ship
Gummi-Ship
  • Member since: May. 30, 2006
  • Offline.
Forum Stats
Member
Level 26
Blank Slate
Response to AS: Sound Aug. 6th, 2006 @ 04:29 AM Reply

this dont help me with wat im doing sorry, if u can help, wat i need 2 do is get a sound 2 stop on 1 frame, and the next 2 play on the same frame. i made a few frames 4 an intro, then i put stop(); on the frames with buttons on, which is everything afta the intro, so if u can, please help me.


Not another smackerel to be found :(

ultimateshadowx9
ultimateshadowx9
  • Member since: Aug. 9, 2006
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to AS: Sound Sep. 11th, 2006 @ 03:05 PM Reply

how do you make a button to change the sound,
srry if you don't understand that

how do you make a button that changes the current sound to a different sound, aka NG10283 to NG8294054

ultimateshadowx9
ultimateshadowx9
  • Member since: Aug. 9, 2006
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to AS: Sound Sep. 11th, 2006 @ 03:55 PM Reply

sombody please help
(hte person who gives me the answer goes on my credits)

Stobble
Stobble
  • Member since: Oct. 20, 2006
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to AS: Sound Oct. 21st, 2006 @ 06:23 PM Reply

Err, i Still don't get it... It says that the music i import has trouble being read or something... So i can't really post anything on newgrounds 'cause they're always blammed because of no sounds... w\e help plz.

23450
23450
  • Member since: May. 28, 2003
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to AS: Sound Oct. 21st, 2006 @ 06:24 PM Reply

At 10/21/06 06:23 PM, Stobble wrote: Err, i Still don't get it... It says that the music i import has trouble being read or something... So i can't really post anything on newgrounds 'cause they're always blammed because of no sounds... w\e help plz.

that has nothing to do with this tutorial, its because the format of the song your importing is not reconized by flash. what format is it in? it should be mp3 or wav ro work properly.


BBS Signature