Wednesday, March 3, 2010

Sound in AS2

This is a short tutorial on how to use sound with as2

First you need to download a song

Then you need to import it into flash 8

File>Import>To Library

Then select your file

On your root time line put the following code

mySound = new Sound(this);
mySound.attachSound("sound1");
mySound.start();

In your library right click on your sound then click linkage...

In the pop up menu make sure the first check box is checked that says "Export for actionscript"

If that is check the first box where you can type in will be available

Type sound1 in that box (or whatever you put in the mySound.attachSound(); function)

The mySound.start(); part of the code can be ommitted and put some where else like

on (release) {
  mySound.start();
}

you can also control the volume of the sound using the setVolume() function like this

on (release) {
  mySound.setVolume(50)
  mySound.start();
}

That will make the sound play at 50% of it's normal volume

Now i will explain panning

Panning is witch speaker the sound will come out of if the panning is -100 then the sound will come out of the left speaker if the sound is 100 it will come out of the right speaker if it is set to 0 it will come out of both speakers

on (release) {
  mySound.setVolume(50)
  mySound.setPan(50)
  mySound.start();
}

That code means that the sound will play at 50% volume and will be herd more out of the left speaker

That is my tutorial if you don't understand the PM me of e-mail me

--Sasuke2910

No comments:

Post a Comment