A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: How do you use the key press to play sounds from the library?

  1. #1
    Junior Member
    Join Date
    Jan 2007
    Posts
    11

    Question How do you use the key press to play sounds from the library?

    Action Script 2.0

    I've been making soundboards for a couple of years, but in my opinion I do it in a rather hacky inefficient way.

    Previously I have been creating a movie clip with the sound on frame 2, and a simple stop on frame 1. I then add code to the movie clip basically saying onkeypress ("Y") gotoandplay frame 2.

    This method takes forever. I am an AS novice, I have wrestled with it on many occasions. I just don't have the brain for it. Was wondering if there's a basic code that you guys could help me with to tell it that when this key is pressed, play this sound in my library.

    Any help appreciated, thanks

  2. #2
    Junior Member
    Join Date
    Jan 2007
    Posts
    11
    I'd have thought this would be an easy one to answer, has no one got anything on this?

  3. #3
    Junior Member
    Join Date
    Dec 2009
    Posts
    1
    Its very simple as you do in your house same thing i do in library in order to URL=http://www.funrocker.com/song-pk.htmlplay song.

  4. #4
    Flashkit historian Frets's Avatar
    Join Date
    Oct 2000
    Location
    flashkit
    Posts
    8,797
    Sj

    You'll find your time here very short if you continue to yank up old threads for the sake of a post count.

  5. #5
    Senior Member
    Join Date
    Jul 2006
    Location
    San Jose, CA
    Posts
    334
    *edit*

    Didn't see you're using AS2. Perhaps this can still push you in the right direction.

    ----

    This could get you started. In main.fla I just have a sound with the Linkage identifier as "Sound1", and this .as file is the DocumentClass.

    PHP Code:
    package {
        
    import flash.events.KeyboardEvent
        import flash
    .display.MovieClip
        
        import flash
    .media.Sound
        import flash
    .media.SoundChannel
        
        
    public class VirtualDJ extends MovieClip {
            private var 
    sChannel:SoundChannel;
            
            public function 
    VirtualDJ():void {
                
    stage.addEventListener(KeyboardEvent.KEY_DOWNonKeyPress)
                
    sChannel = new SoundChannel();
            }
            private function 
    onKeyPress(ke:KeyboardEvent):void {
                
    //trace(ke.keyCode)
                
    var s1:Sound1 = new Sound1();
                
    sChannel s1.play()
            }
        }

    You can check to see which keycode was pressed, play different sounds, etc.
    I (Love | Hate) Flash.
    ----
    Save a version back so others may help you!

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