AS 2 Play sound on key press
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Play sound on key press

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    7

    Play sound on key press

    using CS5 AS2.

    I have frame one using a listener for key presses. I am then converting the key into a KeyCode, then using switch case with that KeyCode to jump to a frame and play a sound_mc. each KeyCode will go to the corresponding letter sound. press "q" the computer plays q sound clip.

    the problem.
    I am testing this using three letters, so on frame 5,6, & 7 I have q_mc , w_mc , & e_mc. on a different AS layer i have a gotoAndPlay(1); so it should start on frame one and wait for a key, when a key is pressed it goes to the frame 5,6, or 7 depending on key. frame 5 works, no matter which mc i place there, but frame 6 plays two sounds, and frame 7 plays all three. so if 5=q 6=w & 7=e the q plays q, w plays q&w and e plays q,w,&e.

    tried
    I have tried many different configurations like moving my gotoandplay(1) a frame after the sound, I have added it to the same layer as the sound_mc, I have tried to label the frames and use the label in the switch case.

    I can link up the file for a closer look if you have cs5 and want to look, any help is greatly appreciated.

    Thank you.

  2. #2
    Junior Member
    Join Date
    Mar 2013
    Posts
    7
    this is a link to the file and assets in dropbox
    https://dl.dropbox.com/u/38197086/keyboard.zip

    feel free to check it out and help if you can.

    also, maybe there is an easier way to accomplish this. for example, maybe instead of gotoandplay a frame I can just play the "letter"_mc. if this can be done, i am unsure of the code, would I place all the sound_mc's on frame one? how would I make it so they don't play until key is pressed? can I play an _mc from the librarywithout it being on the stage/scene

    thanks.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    7
    SWEEEEEETness. I got it, I was in looking at my frame labels and noticed down a little lower in the properties the sound option, instead of using an _mc, I just added the sound here. made me switch case point to the label, and then on the label frame added, gotoandplay(1) to go back to the listener AS.

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

Poll by Flashkit.com