6 Replies Latest reply on Feb 7, 2008 10:37 AM by Rothrock

    Please if somebody could help me

    svarmuza
      Greetings,
      I really don't know action script and I'm sure I can't solve this otherwise, so If somebody could help me I would be grateful.
      I have added sound to a button "over" state, but I would like to start only if mouse pointer stays over button more than 1 sec. I think I need to use some conditional function but I don't know what.
      Thanks in advance.
      Sasa
        • 1. Re: Please if somebody could help me
          clbeech Level 3
          well it's a little tricky but you could use setInterval here to start a 'timer' so to speak, but you also need to make sure to shut it off too. also if you only want the sound to play once or not will be a factor. So in an onRollOver handler you would fire the interval, then after a certain amount of time the sound would play, then you would also include a onRollOut handler, to 'turn off' the interval, if the mouse leaves the button. you will also want to use a Sound Object, as opposed to a timeline or event sound, something like this:

          • 2. Re: Please if somebody could help me
            svarmuza Level 1
            Well I don't quite get it.
            1. I made button play-put it to stage and gave it instance name "play"
            2. I imported sound to library-selected it clicked properties-linkage-and gave indentifier "sound"
            3. I made new layer named actionscript and entered the above code
            4. In
            btnsound.attachSound('btnsound_id');
            I replaced btnsound_id with sound

            5. in
            my_btn.onRollOver = function() {
            I replaced my_btn with play (also I put play.onRollOut )

            When I publish it, there are no errors shown, but sound doesn't load, nothing happens.
            What am I missing.
            Thanks,
            Sasa
            • 3. Re: Please if somebody could help me
              svarmuza Level 1
              Well I don't quite get it.
              1. I made button play-put it to stage and gave it instance name "play"
              2. I imported sound to library-selected it clicked properties-linkage-and gave indentifier "sound"
              3. I made new layer named actionscript and entered the above code
              4. In
              btnsound.attachSound('btnsound_id');
              I replaced btnsound_id with sound

              5. in
              my_btn.onRollOver = function() {
              I replaced my_btn with play (also I put play.onRollOut )

              When I publish it, there are no errors shown, but sound doesn't load, nothing happens.
              What am I missing.
              Thanks,
              Sasa
              • 4. Re: Please if somebody could help me
                svarmuza Level 1
                Still when I publish my swf I don't get any sound when I pass with the mouse pointer over the button. I don't know what am I doing wrong. Is there somebody that could help me with this.
                Thanks in advance.
                Sasa
                • 5. Re: Please if somebody could help me
                  clbeech Level 3
                  well it sounds (very punny ...) like you've done everything correctly here, but the code is designed to play the sound 'after' the mouse has been hovering on the button for at least one second ... you'd said, 'when I pass with the mouse pointer over the button' ... which is why I'm asking :)

                  you also didn't use quotation marks within the sound's identifier (in the sounds Library properties)? right? and selected 'export for ActionScript' and 'export in first frame'?

                  What type of file format is the Sound? it should be mp3, wav or aiff (but mp3 is preferable)

                  I would also suggest changing the instance name of your button to something other than 'play' since that is a reserved word in Flash and may cause problems, use something like 'play_btn' instead.
                  • 6. Re: Please if somebody could help me
                    Rothrock Level 5
                    Add some traces to your code to help visualize what is going on. I'll let you figure out where these go.

                    trace("Button rolled over, timer started.");
                    trace("Button rolled out, timer cleared.");
                    trace("Playsound called. I should hear sound.");

                    And I have a few more tips for you.

                    First, you should always pass an instance of a movieclip to the new Sound contructor. So if you will only have this one sound you should do:

                    var btnsound = new Sound(this);

                    If you will need various types of sounds think about creating a clip for each type and then passing that.

                    Personally I never set and interval without first clearing it. If you set an interval and there is already one running you won't be able to easily clear it. You may technically think that there is no way that it would possible to already have one out there, but see my next point. So anyways I would add this line to the rollOver:

                    clearInterval(timer);

                    You have forgotten one thing. My pet clip event onReleaseOutside. If the user clicks on the button, but then holds the mouse down and moves off the button, you won't have any onRelease event and the timer will keep going. So either you will hear the sound when you aren't visually on the button or (much worse) if you move back over the button before a second is up you will get a never ending 1 second repeat of the audio.

                    You will probably also want to kill the interval onPress or onRelease.