1

Okay, basically, I want to create a button that triggers a new javascript function. I want the button to click and stay clicked (then click again to toggle off).

My code (without button):

function playSound(target) {
            //Play the sound: play (src, interrupt, delay, offset, loop, volume, pan)
            var instance = createjs.Sound.play(target.id, createjs.Sound.INTERRUPT_ANY, 0, 0, false, 1);

            if (instance == null || instance.playState == createjs.Sound.PLAY_FAILED) { return; }
            target.className = "gridBox1 active";

            instance.addEventListener ("complete", function(instance) {
                target.className = "gridBox1";
            });
        }

I want a clickable button to trigger a new set of sounds that loop, this is what I have come up with:

<button id="buttonEv" onclick="myFunction()">Evolve</button>

        <script>

        function myFunction() {

            function playSound(target) {
               //Play the sound: play (src, interrupt, delay, offset, loop, volume, pan)
                var instance = createjs.Sound.play(1, {loop:2});
                instance.on("loop", handleLoop); 

                if (instance == null || instance.playState == createjs.Sound.PLAY_FAILED) { return; }
                target.className = "gridBox1 active";

                instance.addEventListener ("complete", function(instance) {
                    target.className = "gridBox1";
                });
            }

        }

        $('#buttonEv').click(function(event){
            if($(this).hasClass('active')){
            $(this).removeClass('active')
            } else {
            $(this).addClass('active')
        }
        });

        </script> 

The button clicks and stays clicked, though not affecting the sounds

Make sense? Any ideas? Thanks!

John Myers
  • 11
  • 2

0 Answers0