PDA

View Full Version : Sound Effects


Xionraseri
03-01-2008, 12:09 AM
Does anyone know why my sound will not work? Any help greatly appreciated, last step and then game is done.


//from init function
//set up sounds
sndCrash = new Sound();
sndCrash.attachSound("crash.wav");

sndFlame = new Sound();
sndFlame.attachSound("flame.wav");

sndAlarm = new Sound();
sndAlarm.attachSound("alarm.wav");

//from checkKeys function
if (Key.isDown(Key.SPACE)){
//shoot flame
sndFlame.start();
flame._x = monster._x;
flame._y = monster._y;
flame.dir = monster.dir;
flame.speed = monster.speed + 20;
turn(flame);
}//end if

function checkCollisions(){
//check for collisions

if (monster.hitTest(car1)){
trace("hit by car 1!");
sndCrash.start();
reset(car1);
monster.lives --;
if (monster.lives <= 0){
_root.gotoAndStop("gameOver");
}//end if
} //end if

if (monster.hitTest(car2)){
trace("hit by car 2!");
sndCrash.start();
reset(car2);
monster.lives --;
if (monster.lives <= 0){
_root.gotoAndStop("gameOver");
}//end if
}//end if

if (monster.hitTest(car3)){
trace("hit by car 3!");
sndCrash.start();
reset(car3);
monster.lives --;
if (monster.lives <= 0){
_root.gotoAndStop("gameOver");
}//end if
}//end if

// look for flame collision

if (flame.hitTest(car1)){
trace("burned car 1");
sndAlarm.start();
resetFlame();
reset(car1);
monster.points += 100;
}//end if

if (flame.hitTest(car2)){
trace("burned car 2");
sndAlarm.start();
resetFlame();
reset(car2);
monster.points += 100;
}//end if

if (flame.hitTest(car3)){
trace("burned car 3");
sndAlarm.start();
resetFlame();
reset(car3);
monster.points += 100;
}//end if
}//end checkCollisions

pradvan
03-03-2008, 02:17 AM
You have to link the sound files you're trying to use from the library.

sndCrash = new Sound();
sndCrash.attachSound(myCrashSound);

and link "crash.wav" to myCrashSound, just like you would a movieclip.

Xionraseri
03-06-2008, 12:40 AM
Er...How do I link 'crash.wav' to 'myCrashSound'? Sorry, I'm rather new to coding.

pradvan
03-06-2008, 02:29 AM
Right-click on the wav file in the library
Select Linkage
Check "Export for ActionScript"
Enter "myCrashSound" in the Identifier field

and that's it :)

Xionraseri
03-06-2008, 05:13 AM
Thanks, sorry for the noob questions.