A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: sound with key press

  1. #1
    Relaxing tmoore935's Avatar
    Join Date
    Oct 2001
    Location
    colorado, usa
    Posts
    1,713

    sound with key press

    How do I get sound to activate with a key press? I can get objects to move around the screen. But I want a sound to happen when I press a key. And would I import the sound?
    Any programming language is at its best before it is implemented and used.

  2. #2
    undead creature necromanthus's Avatar
    Join Date
    Feb 2002
    Location
    ROM
    Posts
    1,890
    Do in this way:
    1)Create an empty movie clip with 4 keyframes named "snd"
    2)Insert STOP for keyframes 2 and 4
    3)Add the desired sound on keyframe 3
    4)In the main timeline add this script:

    if(Key.isDown(what you need)) {_root.snd.gotoAndPlay(3);}

    that's all !

  3. #3
    Relaxing tmoore935's Avatar
    Join Date
    Oct 2001
    Location
    colorado, usa
    Posts
    1,713
    Originally posted by necromanthus
    Do in this way:
    1)Create an empty movie clip with 4 keyframes named "snd"
    2)Insert STOP for keyframes 2 and 4
    3)Add the desired sound on keyframe 3
    4)In the main timeline add this script:

    if(Key.isDown(what you need)) {_root.snd.gotoAndPlay(3);}

    that's all !
    I can not get this to work

    I create a new movie clip. then create 4 keyframes. in frame 3 i added sound and used stop movie for 2 and 4.
    in the main movie I went to sound and actions and added
    if(Key.isDown(key.SPACE)) {_root.snd.gotoAndPlay(3);}
    In the main movie i changed the mc name to snd.
    any suggestions?
    Thank you.
    Any programming language is at its best before it is implemented and used.

  4. #4
    Senior Member
    Join Date
    Jun 2001
    Posts
    289
    Just a thought - I had a problem with keyboard stuff, until Hilary advised me to first click in the movie (to give it focus). Thereafter it knows the keys are for it (or at least until you click outside the movie and transfer focus elsewhere).

  5. #5
    Relaxing tmoore935's Avatar
    Join Date
    Oct 2001
    Location
    colorado, usa
    Posts
    1,713
    Originally posted by OwenAus
    Just a thought - I had a problem with keyboard stuff, until Hilary advised me to first click in the movie (to give it focus). Thereafter it knows the keys are for it (or at least until you click outside the movie and transfer focus elsewhere).
    I tried the focus. It is something simple. I need to sleep on it.
    This is for an old arcade style game that I am about half way thru. I want a laser sound when a laser is fired with the space key.
    Last edited by tmoore935; 11-13-2002 at 11:52 PM.
    Any programming language is at its best before it is implemented and used.

  6. #6
    undead creature necromanthus's Avatar
    Join Date
    Feb 2002
    Location
    ROM
    Posts
    1,890
    I don't know what are you doing wrong.
    Works perfect for me !
    OK ... try this modification:
    1) delete the command line from the main timeline.
    2) add this script for the child-movie "snd":

    onClipEvent(enterFrame){
    if(Key.isDown(key.SPACE)){this.gotoAndPlay(3);}
    }

    cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center