1 Reply Latest reply on Nov 9, 2017 7:29 AM by kglad

    Sound does not play

    Marampazú Level 1

      Hello again.

       

      I'm doing tests for a little game that I'm developing.

      The game is type Simon says, so I need buttons with click to play your movie / sound. When it is the turn of the CPU the aimations of the cards should be shown automatically, for this I implemented the following code:

       

      -----------------------------------------------------

      createjs.Sound.registerSound ("audios / audio_red.mp3", "audioRed");

      root = this;

       

      this.btn01.on ("click", function () {

           createjs.Sound.play ("audioRed");

           root.mcClic.gotoAndStop (0);

           root.mcClic.play ();

      });

       

      this.mcClic.on ("click", function () {

           createjs.Sound.play ("audioRed");

           root.mcClic.gotoAndStop (0);

           root.mcClic.play ();

      });

       

      function sounds () {

           alert ("hi");

           createjs.Sound.play ("audioRed");

      }

       

      sounds();

      --------------------------------------------------------

       

      First I made a movieclip that can be clicked to play its animation / sound, this is the movie mcClic. It works, but you can not make multiple clicks.

       

      Then I made a button that controls the same movieclip, this button allows multiple clicks and the animation and sounds are repeated according to the clicks. Here comes the first doubt, I think I understand that it does not work because I'm clicking on a movieclip.

       

      Finally, at some point I need the sound / animation to be reproduced automatically to show what the user should throw away. I already have an arrangement and plan to go browsing element by element. However, for my first tests I sent for the first element to be played automatically. Basically it would execute the function sounds (). This does not work, although the alert does not play the audio. Although it does not come in this code snippet, I also included executing the animation of the button, which it does not either.

       

      Can you help me? I do not know if you are omitting something or have to write the code in another way.

       

      Thanks for your support.

        • 1. Re: Sound does not play
          kglad Adobe Community Professional & MVP

          hi,

           

          your mp3 hasn't loaded when you call sounds() so that one will fail.  the others (assuming you don't click too quickly) will work (if your path/name to the mp3 are correct).  ie, use an fileLoad event listener before playing your sound:

           

          replace:

           

          sounds();

           

          with:

           

          createjs.Sound.addEventListener('fileLoad',sounds);