• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Sound does not play

Community Beginner ,
Nov 08, 2017 Nov 08, 2017

Copy link to clipboard

Copied

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.

Views

443

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 09, 2017 Nov 09, 2017

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);

Votes

Translate

Translate
Community Expert ,
Nov 09, 2017 Nov 09, 2017

Copy link to clipboard

Copied

LATEST

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);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines