Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Play sound when key is pressed, how?

New Here ,
Oct 09, 2010 Oct 09, 2010

Hello!
I have googled the question but I didn't get any answare that helped.

Alright so I'm creating a car game, I have a soundclip in my library called "engine"
And I want it to play all the time except when I press the up button. When I press the up button I want my other sound "engine_2" to play when the key is pressed down and when released "engine" should start again.
Both sounds should loop all the time when played.
I'm a beginner with AS2 so be easy

Thank you.

TOPICS
ActionScript
983
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 09, 2010 Oct 09, 2010

//outside your loop (that you must have), use:

var s:Sound=new Sound(this);

var engineBool:Boolean;

var engine2Bool:Boolean;

// and inside your loop, use:

if (Key.isDown(Key.UP) && !engine2Bool) {

s.attachSound("engine_2ID");   // assign engine_2 a linkage id of engine_2ID;

s.start(0,999);

engine2Bool=true;

engineBool=false;

} else if(!engineBool){

s.attachSound("engineID");  // assign engine a linkage id of engineID

s.start(0,999);

engineBool=true;

engine2Bool=false;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 10, 2010 Oct 10, 2010

Sorry I don't understand what you mean with inside and outside the loop

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 10, 2010 Oct 10, 2010
LATEST

can you control your car?  if yes, what code are you using to control your car?


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines