3 Replies Latest reply on Nov 16, 2006 5:32 PM by mirianam

    Play sound fx once a second

    mirianam Level 1
      I have a countdown timer that countdowns from 25 seconds.
      I would like to add a "tic" sound fx which plays once every second but can't get my head around how to do this
      Here is the code I am using for the countdown.
      Can anyone guide me on this please.

      global gScore

      -- behaviour script attched to a text sprite
      on beginSprite me
      gScore = 0
      sprite(me.spriteNum).member.text = "0:25"
      startTimer()



      end beginSprite


      on enterFrame me
      tSecElapsed = (the timer)/60
      if tSecElapsed < 25 then
      tTime = 25 - tSecElapsed
      tSec = tTime mod 60
      if tSec < 10 then
      tSec = "0" & tSec
      end if
      tMin = tTime/60
      sprite(me.spriteNum).member.text = tMin & ":" & tSec
      else
      sprite(me.spriteNum).member.text = "0:00"
      end if

      if gScore = 55 then pass
      else

      if sprite(me.spriteNum).member.text = "0:00" then
      go to "drown"
      sound(4).play(member("LiquidDrops"))
      end if
      end if
      end enterFrame
        • 1. Re: Play sound fx once a second
          Level 7
          See additions to your code below

          "mirianam" <webforumsuser@macromedia.com> wrote in message
          news:ejh2d3$ora$1@forums.macromedia.com...
          >I have a countdown timer that countdowns from 25 seconds.
          > I would like to add a "tic" sound fx which plays once every second but
          > can't
          > get my head around how to do this
          > Here is the code I am using for the countdown.
          > Can anyone guide me on this please.
          >
          > global gScore
          >
          property pCurrentSec
          > -- behaviour script attched to a text sprite
          > on beginSprite me
          > gScore = 0
          pCurrentSec = 25
          > sprite(me.spriteNum).member.text = "0:25"
          > startTimer()
          >
          >
          >
          > end beginSprite
          >
          >
          > on enterFrame me
          > tSecElapsed = (the timer)/60
          > if tSecElapsed < 25 then
          > tTime = 25 - tSecElapsed
          if tTime < pCurrentSec then
          pCurrentSec = tTime
          -- play your sound here
          end if
          > tSec = tTime mod 60
          > if tSec < 10 then
          > tSec = "0" & tSec
          > end if
          > tMin = tTime/60
          > sprite(me.spriteNum).member.text = tMin & ":" & tSec
          > else
          > sprite(me.spriteNum).member.text = "0:00"
          > end if
          >
          > if gScore = 55 then pass
          > else
          >
          > if sprite(me.spriteNum).member.text = "0:00" then
          > go to "drown"
          > sound(4).play(member("LiquidDrops"))
          > end if
          > end if
          > end enterFrame
          >
          >


          • 2. Re: Play sound fx once a second
            duckets Level 1

            You'll need to add a property to your behaviour which remembers the 'seconds' value from the previous frame, and only play a sound if the current 'seconds' differs from what it was the previous frame. I've attached a modified version below. The extra code is added after the line where you assign 'tSec'. I've also added a property to store the sprite reference which neatens the code (sorry, I'm a bit obsessive with that sort of thing!)

            • 3. Re: Play sound fx once a second
              mirianam Level 1
              Thank you very much for your help
              I tried so many different things but I was heading in a completely wrong direction.