Skip to main content
April 10, 2013
Question

Actionscript

  • April 10, 2013
  • 2 replies
  • 414 views

What code is needed to control when the viewer can advance?  For example:  The viewer must listen to 4 different sound files all listed at the same time before being able to click to advance.

This topic has been closed for replies.

2 replies

Inspiring
April 10, 2013

Here is what I do:

This is a setup that happens once.

var numSounds:int=4

var allHeard:int=Math.pow(2,numSounds)-1

var listenCount:int=0;

Then I give each sound (or the button that starts the sound) a number from 0 to numSounds-1. I usually call that ID or myID.

When each sound has been listened too I have some code that does marks that it has been heard and checks to see if we are all done:

listenCount |= 1<< currentSound.ID;

if(listenCount>=allHeard){

     trace("All done we can move along now.");

}

The cool part about this is that you can change it for from 1 to 31 different things you need to track just by changing the numSounds variable. Remember that you need to start giving your ID numbers from zero and they must be consecutive.

kglad
Community Expert
Community Expert
April 10, 2013

some logic.

for example, if each listened-to sound also set a boolean variable (eg, sound1Listened etc) then you could use:

if(sound1Listened&&sound2Listened&&...){

// advance (eg, gotoAndStop)

}