actionscript 3 - Playing laser sound while pressing spacebar as3 -


trying figure out code ship when press spacebar , fires laser sound 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 worked 2 things need add

import flash.net.urlrequest; import flash.media.sound; 

you can try if have external sound in "audio" folder

var reqbutton:urlrequest = new urlrequest("audio/button.mp3");  var buttonsound:sound = new sound(reqbutton); 

and 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;           }     } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -