flash + sound question

Soldato
Joined
13 Dec 2002
Posts
7,646
Location
Manchester City Centre
I've made a small flash presentation type thing to go with a new recruitment campaign at my work, as part of the same campaign there's a radio advert running, and they want that to play over the presentation, which i've got working fine
the problem i have is that i only want it to play for the 1st loop of the presentation i.e. it plays once and then the presentation continues without any sound

any ideas of the best way to do this?
i presume putting some event in with a counter would be simplest, but i'm not really very good with flash so unsure how i'd do that
any help much appreciated
 
example..

open a new fla, import a sound to the library. in the library right click the sound file and select linkage. tick 'Export for Actionscript' and 'Export in first frame'.

frame1..
Code:
var sndPlayed:Boolean;
//start volume
var nVol:Number = 0;
//fade stepping
var nStepping:Number = 5;
//fade speed in ms
var nMs:Number = 100;

function fadeIn():Void {
	// stepping of volume increase
	nVol += nStepping;
	mySound.setVolume(nVol);
	if (nVol>99) {
	clearInterval(nfadeInInterval);
	}
}

function fadeOut():Void {
	// stepping of volume reduction
	nVol -= nStepping;
	mySound.setVolume(nVol);
	if (nVol<1) {
	clearInterval(nfadeOutInterval);
	mySound.stop();
	}
}

start loop frame..
Code:
switch (sndPlayed) {
case undefined :
	trace(sndPlayed);
	var mySound:Sound = new Sound();
	mySound.attachSound("yourSound.mp3");
	mySound.setVolume(nVol);
	mySound.start();
	// every nMs volume will increase by nStepping
	var nfadeInInterval:Number = setInterval(fadeIn, nMs);
	sndPlayed = true;
	break;
case true :
	trace(sndPlayed);
	// every nMs volume will decrease by nStepping
	var nfadeOutInterval:Number = setInterval(fadeOut, nMs);
	break;
}
basicaly..
sndPlayed = undefined, add sound, start it, fade it in and set the fact it's been played.
sndPlayed = true, a complete loop has been done, fade it out and finaly stop.

the best method depends on the project, if it's a local app then the above is good.. but if it's for the web then exporting to the first frame can foul preloaders if used. foul as in the data for the items that where set to be exported, loads before the preloader is even shown :o then it may be best to use a new movieclip with the sound placed into it, with as many frames as the sound lasts, a stop(); on it's frame 1 and then placed onto the stage after the preloader.

i'm rushing a bit here now because i have to get some things done and i'm going to get moaned at soon :D
 
Back
Top Bottom