6 Replies Latest reply on Aug 22, 2007 9:35 AM by SymTsb

    Actionscript button, keyPress

    shurleynova Level 1
      I am having a problem getting me movie to play sounds when I press the spacebar

      It plays the sounds without me pressing anything, like my button is possessed. Help

      No seriously the actions to play the sound are on one frame and the button is off stage because I dont want people to click it I want them to press the spacebar. But as soon as I play the movie it plays the sound in time with the frame rate, so it seems like the button is pressing itself.

      I think my error might be in the way I am telling it I want the space bar to activate the button

      I am still getting the hang of the dot notation thing so don't laugh

      Not sure here


      Doesnt seem to work

      Here is thw whole thing in case anyone can help:
        • 1. Re: Actionscript button, keyPress
          SymTsb Level 2
          This would be a lot easier in just plain AS2.

          Create a Key handler (read flash help on the Key Class). Add an event listener to the root timeline that checks button presses (specifically targeting the ascii value of the space bar) and when that occurs, tell your sound to start playing. If you want the space bar press to turn the music on and off you'll also need to set a boolean of some sort and test it based on whether the music is on or off. It should be a fairly simple routine to write after you read the Key class.
          • 2. Re: Actionscript button, keyPress
            shurleynova Level 1
            Ok this sorta worked but now it is doing what I was trying to work around before

            Now it is playing both sounds at the same time when I press the button.
            I have tried creating new clips, two buttons and disabling one, the Key handler makes good sense but maybe I am missing something.

            Help anyone this is making me nuts
            • 3. Re: Actionscript button, keyPress
              shurleynova Level 1
              oh and btw snds is a variable loaded through an XML so its value changes as the flash parses the XML this all takes place in a single frame on the timeline through a setInterval controlled looping of data in a XML file.

              The object here is if the user presses the spacebar in time they get a happy beep sound, but if they are too late they get a buzz sound.
              • 4. Re: Actionscript button, keyPress
                SymTsb Level 2
                I am pretty sure now that I understand what you are doing which raises questions as to why you are loading in an xml value since it isn't really necessary when you only have two sounds. Based on the info you've provided, I believe tour timer function needs one more little line that sets a boolean value to true when the right time is met and to false when it is not. Then you can do this....

                • 5. Re: Actionscript button, keyPress
                  shurleynova Level 1
                  ok that helped, I also added one extra line with stopAllSounds before it starts the sound. This fixed another instance where it was overlapping a bit.

                  To answer your query I am loading more than sound values through the XML
                  the entire movie is generated by getting values each pass around a loop to move various objects and display them at variouos locations the sound value just happens to be one of the attributes of each node that is passing through. Iwas easier to do it this way since there are 100 instances of the objects that need to be displayed before the end of the movie.

                  Thanks for the Help

                  • 6. Re: Actionscript button, keyPress
                    SymTsb Level 2
                    Ahh ok. Well I'm glad I could help.