Controlling Audio with ActionScript 2
There are several ways to manipulate audio with ActionScript 2. See the following for an overview of interacting with sound in code:AS2 Sound Class
Stopping Audio
Stopping Audio
Normally, all that's required is the usual: stopAllSounds();
We do this normally For courses that have background audio, however, this may not be ideal. In those cases, it's possible to use the following method:
- Remove stopAllSounds from your question's submit/continue buttons
- Place the following code onto your question's submit button and continue button where stopAllSounds(); used to be:
var questionAudio:Sound = new Sound(this); questionAudio.stop();
- Test that your question audio stops properly and does not interfere with the main timeline's audio.
The trickery here is that in creating a sound using new Sound();
, we pass in this
, telling the code that it should refer to the MovieClip that contained the code. You can also pass in a separate MovieClip to control that MovieClip's audio instead.