4 Replies Latest reply on Nov 21, 2015 6:01 PM by CactusZeus

    html5 canva. conditional javascript function to start sound, pause and resume with only one button

    CactusZeus Level 1



      I'm trying to rewrite my as3 code for my flash html5 canva and i'm facing some issues with javascript / soundJs syntax.


      I figured out how to pause and resume  my sound on mouseover/mouseout out  but I'm still not abble do it with only one button.

      Indeed my button needs to be also the one that triggers the sound from the start (since the reactive zone of my button is all over my banner ).


      I think i'm missing a conditionnal function to check if the sound is playing or not. And then pauses it or starts it from the beginning if not played.

      My javascript syntax is too limited and i'm still trying.


      So far here's my code in JS:


      var frequency = 3;
      function fl_MouseOverHandler(){  
         exportRoot.soundInstance = playSound("monstres");
      this.bout_zone_son.addEventListener("mouseover", fl_MouseOverHandler);  
      function fl_MouseOutHandler()  {  
      this.bout_zone_son.addEventListener("mouseout", fl_MouseOutHandler);  
      function fl_MouseOverHandler_2(){  
      this.bout_zone_son_2.addEventListener("mouseover", fl_MouseOverHandler_2); 
      this.bout_zone_son_2.addEventListener("mouseout", fl_MouseOutHandler);


      As you can see, I need 2 separate buttons so far. One to start the sound and another to pause and resume it.


      In AS3, I was able to declare a variable on the first frame "telling" the sound is not paused:


      __pause == false;


      and when hovering my button this function was checking weither the sound was paused or not and then play it or resume it from where it has been paused:


      function play() {
           if (__pause == false) {
              __monSon = new Sound(this);
              __monSon.loadSound("monstre_bannieres.mp3", true);
          } else {
             __monSon.start(__savePosition); // this equals to resume(); in soundJS and works perfectly
             __pause = false;


      If anyone have a hint to convert this is javascript I'd be so grateful.

      Thank you for your time.