EnhancedSound is a sub class of built-in Sound class, which extends
Sound with some extra properties and methods.
The properties and the methods of Sound are available as they are, with
this EnhancedSound as well.
Properties added (All optional)
file
defaultVolume
Used for the methods 'fadeOut' and 'fadeIn'
dontOverLap
A boolean value which specifies whether the sound can be played
overlapping itself when it's already playing. If true, it stops
the previous play before it starts.
offset
loopCount
xPosPan
An x coordinate number value which sets its panning position.
i.e. Assigning 0 to xPosPan sets the pan to leftmost and Stage.Width
to rightmost.
Methods added
setDefaultVolume
setDontOverlap
setOffset
setLoopCount
setXPosPan
Can be useful when you want the sound's pan to follow the mc's
_x.
mySound.setXPosPan(0) is equivalent to mySound.setPan(-100).
mySound.setXPosPan(Stage.Width) is equivalent to mySound.setPan(100).
play
Equivalent to 'start' of Sound, except it supports 'dontOverlap'
and switching 'file'.
fadeOut
Fades-out the sound during the time specified with the passed milliseconds
value.
fadeIn
Fades-in the sound during the time specified with the passed milliseconds
value.
Optionally, you can specify the file to play at this time as well.
Usage example 1
// "bell.wav" and "buzzer.wav"
in the library of _level10
_level10.createEmptyMovieClip("SE_bell_mc", 1);
_level10.createEmptyMovieClip("SE_buzzer_mc", 2);
// The parameters, except the first one which specifies the timeline,
are all optional.
_global.SE_bell = new EnhancedSound(_level10.SE_bell_mc, "bell.wav");
_global.SE_buzzer = new EnhancedSound(_level10.SE_buzzer_mc, "buzzer.wav",
70, true, 0.008, 0, Stage.Width*0.7);
SE_bell.play();
SE_buzzer.play();
Usage example 2
// "song1.wav" and "song2.wav"
in the library of _level1
_global.BGM1 = new EnhancedSound(_level1, null, 50, true, 0, 9999);
BGM1.play("song1.wav");
// You may switch 'file' to another at a later time
BGM1.play("song2.wav");
// Also you may do something like this to cross-fade two BGMs.
// "song3.wav" in the library of _level2
_global.BGM2 = new EnhancedSound(_level2, "song3.wav", 50,
true, 0, 9999);
BGM1.fadeOut(3000);
BGM2.fadeIn(3000);
|