mardi 9 mars 2010

Flash scripting and sound, load, play, loop

Sound is very important in every app. On the other hand it is a layer which has not too much to do with scripting. So we just have to know how to load a sound (since we keep the media external), how to play a sound, and how to loop a sound.

Flash does not like .wav sounds! So .mp3 is needed.

This is a very nice link for scripting examples around using sound in FLASH:
http://www.republicofcode.com/tutorials/flash/as3sound/

it tells you how to load an external sound, using URLRequest,
how to make it stop and pause and play again
(using soundChannel and eventlisteners)

how to change the volume, using soundtransform

The only thing I don’t find on this page is how to loop a sound:
this is done using the parameters in the play() function:

mySound.play(0,int.MAX_VALUE);

which means start at position 0 but repeat it the maximum possible number of times! (Which is quite sufficient, thank you very much, for most of the looped sounds…)

This last trick is found here: http://board.flashkit.com/board/showthread.php?t=769120

Aucun commentaire:

Enregistrer un commentaire