Q:

trigger sound effects when mc hits a mc! FLASH AS3

i have two mcs, i want this mc to hit another mc which then plays a loud bang. How would i do this? I'll be using a keyboard event to go with it as well. 
Thanks 

A:

Create a new Flash ActionScript 3 document. be save.
Put your sound like names boom.mp3 in same directory.
Draw a square shape on the stage and convert it into a Movie Clip symbol.
Put a total of 2 instances of this Movie Clip symbol on the stage.
Bring up the Actions panel and add the following code.

Code below, simply drag the mouse to mc1 and mc2 collision when sound is played. is a basic collision with sound playback.

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

mc1.addEventListener(MouseEvent.MOUSE_DOWN, drag);
stage.addEventListener(MouseEvent.MOUSE_UP, drop);
var sound:Sound=new Sound();
sound.load(new URLRequest("boom.mp3"));

function drag(e:MouseEvent):void
{
    mc1.startDrag();
}

function drop(e:MouseEvent):void
{
    mc1.stopDrag();

    if (mc1.hitTestObject(mc2))
    {
        trace("Collision detected!");
        sound.play(0);
    }
    else
    {
        trace("No collision.");
    }
}

If you want using a KeyboardEvent try this:
function playIsCollision(char:DisplayObject, target:DisplayObject):void
{
    if(char.hitTestObject(target))
    {
        sound.play(0);
    }
}

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);

function keyDownHandler(e:KeyboardEvent):void
{
    if(e.keyCode == Keyboard.RIGHT)
    {
        trace("right move");
        mc1.x += 1;
        playIsCollision(mc1,mc2);
    }
    else if(e.keyCode == Keyboard.LEFT)
    {
        trace("left move");
        mc1.x -= 1;
        playIsCollision(mc1,mc2);
    }
    else if(e.keyCode == Keyboard.UP)
    {
        trace("up move");
        mc1.y -= 1;
        playIsCollision(mc1,mc2);
    }
    else if(e.keyCode == Keyboard.DOWN)
    {
        trace("down move");
        mc1.y += 1;
        playIsCollision(mc1,mc2);
    }
}

here is my code: Collision

