Wednesday, 28 March 2012

Adding music and sound effects to the site

I wanted to add some background music to the home page so I looked in Google for royalty free music and came across a site called stockmusic.com. On this site I found some olympic music and in particular a piece of music called Victorious which I thought would be good to use on my home page. I also found sound effects on this site that I could use when the user hovered or clicked on my illustrations of Ali participating in one of the sports. So I purchased 4 sound effects and the Victorious music from this site to add to my site. To add the music and sound effects to my site was similar to how I added the voice overs to the site. Below is the code to add the Victorious music to my homepage and to stop it playing on the other pages.

stop();

var homeSound1:homeSound = new homeSound();
var venuesSound1:venuesSound = new venuesSound();
var gamesSound1:gamesSound = new gamesSound();
var colourinSound1:colourinSound = new colourinSound();
var victorious1:victoriousSound = new victoriousSound();
var sc:SoundChannel;
var isPlaying1:Boolean = true;



if (isPlaying1 == true)
{

sc = victorious1.play();
var videoVolumeTransform:SoundTransform = new SoundTransform();
videoVolumeTransform.volume = 0.20;
sc.soundTransform = videoVolumeTransform;

}

Then so it only played on the Home page I added the following bit of code to all the other pages.

sc.stop();

Adding this code meant the Victorious music would only play on the Home page.

To add the sound effects to the pictures of Ali participating in the sports I added the following code and then for each of the pictures I changed the name of the sound effect. The code below is for the track and field sound effect:

stop()
sc.stop();
var homeSound2:stadiumSound = new stadiumSound();
var venuesSound2:venuesSound = new venuesSound();
var gamesSound2:gamesSound = new gamesSound();
var colourinSound2:colourinSound = new colourinSound();
var trackandfieldSound2:trackandfieldSound = new trackandfieldSound();

trackandfieldpic.addEventListener(MouseEvent.ROLL_OVER, onTrackandfieldPic);

function onTrackandfieldPic(e:MouseEvent):void
{
trackandfieldSound2.play();

}

Adding this code meant when the user hovered over the pictures on each of the venues pages a sound effect would play relating to that sport.

No comments:

Post a Comment