Drag
the qwiSndObj movie clip from the shared Library "qwiSndObj"
to the stage (usually outside of it).
There
are two ways to use this object:
1)
Select the qwiSndObj movie clip instance and give it a name. Change
the sound properties in the Clip Parameters panel:
-
sndID : name of sound linkage ID
- sec : number of seconds of the sound (under Library/Sound Properties)
- secOffset : seconds offset to start playing (0 to start from beginning)
- nLoop : number of times to loop the sound
- autoStart : if this is equal to "true" then sound starts automatically
Call
method: <qwiSndObj instance name>.methodName()
e.g. if (sndObj.isBusy()) { do whatever }
2)
Create a new sound object in script:
var
mySnd = new Sound(level);
// specify the level or use 'this' (if it is referring to the current timeline)
// this ensures the sound will still play if the movie is loaded into a different level
Call
method: <Sound object>.methodName()
e.g. mySnd.init(sndID, sec, secOffset, nLoop, autoStart);
if
(mySnd.isBusy()) { do whatever }
Call
by <Sound object name>.methodName():
init(sndID,
sec, secOffset, nLoop, autoStart)
-- use with script-defined "new Sound()" objects
startSnd()
stopSnd()
isBusy()
getSndEndTime()
Call by <qwiSndObj instance name>.methodName():
startSnd()
stopSnd()
isBusy()
getSndEndTime()
In
this movie, the qwiSndObj movie clip instance is named "sndObj".
To
start the sound named "sndLoop" specified in the clip parameter:
sndObj.startSnd();
To
check if the sound has finished playing:
if
(sndObj.isBusy()) { do whatever }
or
if
(!sndObj.isBusy()) { do something else }
To
get the time when the sound is supposed to finish:
sndObj.getSndEndTime();
To
stop the sound:
sndObj.stopSnd();
Another
sound in this movie is created like this:
mySnd
= new Sound(this);
mySnd.init(sndID, sec, secOffset, nLoop, autoStart);
Apply
the new methods and functions:
mySnd.isBusy()
mySnd.getSndEndTime();
The
"mySnd Vol" button toggles between 25% & 100% sound volume.
When
the movie starts, mySnd starts playing automatically. When it is done,
another sound mySnd2 (14 seconds long) automatically starts playing
from an offset at 12 seconds and loops twice. At the end of mySnd2,
mySnd3 starts playing and it is the same sound as the first sound, except
it loops twice and is started using startSnd().