2020 CSP Unit 3 Lesson 7 Bubble 7

2020 CSP Unit 3 Lesson 7 Bubble 7: I am looking at this debugging exercise and know that we teach students not to place onEvent blocks inside other onEvent blocks. Could someone walk through what actually happens when the onEvent for the down button, play button and stop button are inside the onEvent for the up button?

The app works if you play the up button, and then click and press the play and stop buttons multiple times. But once you hit the down button, the stop button no longer stops the sound and the play button seems to play multiple instances of sound (as many as you click on play button).

I’ve told students many times not to do this, but want to be able to explain what is actually happening.

There may be valid reasons for putting onEvent inside another onEvent. Having said that, I don’t know of any at the moment that couldn’t be done another way.

In this example what happens is there are multiple event handlers for the three buttons down, play, and stop after you push the up button the second time and subsequent times. So when you press the play button you get playSound called many times. One for each event handler you created by pressing up. When you press stop it calls the same number of event handlers with stopSound, but what looks like is happening, at least on my Chromebook, is that calling stopSound() with no parameters only stops the latest sound that was started no matter how many times it is called. So only the last invocation of playSound is shut off and the music continues to play.

Looking at the documentation for stopSound we get Failed request 404. So we don’t know if that is supposed to happen or not. In fact the music keeps going even after I press reset. I have to reload the page to get it to stop. I am guessing there is at least one bug in App Lab there.

Thanks so much! I extricated the onEvents so that they were all independent. And if I pressed the play button twice and then the stop button, the stop button would not stop the second instance of the sound. And it is strange the music keeps going after you press the reset button. Thanks!

I was able to find some older documentation for stopSound. It looks like stopSound() with no parameters is supposed to stop all sounds that are playing. It doesn’t.

Perhaps someone in the inner circle will submit it as a bug.