Playing laser sound while pressing spacebar as3

Trying to figure out a code for my ship when i press spacebar and fires the laser a sound will play

private var reqButton:URLRequest = new URLRequest("laser.mp3");
private var buttonSound:Sound = new Sound(reqButton);

if (key.isDown(Keyboard.SPACE))
            {
                fireBullet();
                buttonSound.play();
            }

ok this worked the only 2 things i need was to add

import flash.net.URLRequest;
import flash.media.Sound;

Answers


You can try this if you have an external sound in an "audio" folder

var reqButton:URLRequest = new URLRequest("audio/button.mp3"); 
var buttonSound:Sound = new Sound(reqButton);

and then your keypress code:

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
    function keyDown(event:KeyboardEvent):void
    {

        switch(event.charCode)
        {   
        case 32:  //Space Bar 
            //trace("Space Bar");
             buttonSound.play();
            break;


        }
    }

Need Your Help

Pass the value by using href

jquery html asp.net-mvc asp.net-mvc-4 jqgrid

I use the following formatter option for add href button in last column of the jqgrid.Its working Fine.

How to find the exact match using GREP

regex bash grep

HI I have a fairly big Log File and want to see which sort of website being requested.