4 Replies Latest reply on Sep 15, 2007 7:07 AM by clbeech

    Key Press Anyone? SImple Q?

      Hi, and thanks in Advance!!!

      So i have a button that needs to be activated from the key board.

      Does anyone have a completed script that will allow the user to activate this button that has sound attached to it from hitting the letter "A" ?

      Also, the sound file that i want to have play on the button is on the "Down State" of pressing. I kinda of need the sound to play in both instances. When the letter on the keyboard is clicked and when you actually use your mouse.


      Thanks A Million! I

      Adam
        • 1. Re: Key Press Anyone? SImple Q?
          Ardy15jan Level 1
          Try listening for keyboard events.
          ActionScript 2.0:
          • 2. Re: Key Press Anyone? SImple Q?
            Ardy15jan Level 1
            ... and ActionScript 3.0:

            • 3. Re: Key Press Anyone? SImple Q?
              Ardy15jan Level 1
              I hope I helped. Also, if you want a suggestion on how to play your sound both in the button and when you press "A", try making a MovieClip on the stage that contains the sound, place it in the 'Over' state of your button and load it dynamicly when user presses "A".
              Best of luck!
              • 4. Re: Key Press Anyone? SImple Q?
                clbeech Level 3
                You can't really call to a button instance to 'activate' it, you could do so if your 'button' is an MC. I would recommend using a Sound Object on the timeline for your event sound, then you can control it from either call, the keyboard or the button. Ardy15jan, has the correct calls for the keyboard above, just add aditional code for your button instance to activate the sound.

                To construct a Sound Object, you will need to import the sound to the library, and add a 'linkage identifier', like 'sound_id' then attach the sound in script on the first frame of the main timeline like so:

                var mySound:Sound = new Sound();
                mySound.attachSound('sound_id');

                ...Then, construct an on handler for the button instance and call the sound:

                myButton.onPress = function() {
                mySound.start();
                }

                ...and in the code for the keyboard as above where Ardy15jan has 'Activate you button' place the start() method:

                mySound.start();

                ...there you go :)