2012-05-03 53 views

回答

1
var spacebarDown:Boolean = false; 

stage.addEventListener(KeyboardEvent.KEY_DOWN, _keyHandler); 
stage.addEventListener(KeyboardEvent.KEY_UP, _keyHandler); 

function _keyHandler(e:KeyboardEvent):void 
{ 
    if(e.keyCode == 32) 
    { 
     switch(e.type) 
     { 
      case KeyboardEvent.KEY_DOWN: 

       if(!spacebarDown) 
       { 
        spacebarDown = true; 

        // Play Sound. 
        var sfx:YourSound = new YourSound(); 
        sfx.play(); 
       } 

       break; 


      case KeyboardEvent.KEY_UP: spacebarDown = false; break; 
     } 
    } 
}