PDA

View Full Version : As?


suicidal-kid
07-06-2006, 07:38 AM
I am in need of help with a code. I suck at actionscript.

I need a code that will make it so when one MC is hit by a second MC a sound will be played. I had a code that would play it once and only once. That is no good. I need it to be able to play the sound the first time it hits and every time after that. My idea for this game need this kind of code.

The first MC will be able to be dragged into the path of the second MC, thus them both hitting. I need said code to be able to hande many first MC's.

Thanks in advance.

Also, if this game does half as will as I hope it will, I will be more than happy to give credit.

stiakooo
07-06-2006, 08:07 AM
Hello!
You can use hitTest() method and Sound object to make that.
Here's an example:
Make new flash document. Import your sound to the Library (File/Import/Import to Library). Right-click your sound in the Library and select Linkage.... In the Linkage Properties dialog box check "Export for Action Script". In the Identifier field enter "sound1" (without quotes). Click OK.
Create your 2 MovieClips and place them on the stage. Give them an instance names - "mc1" and "mc2".
Select the first frame in the timeline and open the Actions panel (F9).
Paste the following AS:
var snd:Sound = new Sound();
snd.attachSound("sound1");
var isDragging:Boolean = false;
var isOver:Boolean = false;
mc1.onPress = function() {
this.startDrag(false);
isDragging = true;
}
mc1.onRelease = mc1.onReleaseOutside = function() {
this.stopDrag();
isDragging = false;
}
mc1.onMouseMove = function() {
if(isDragging) {
if(this.hitTest(mc2)) {
if(!isOver) {
isOver = true;
snd.start();
}
} else {
isOver = false;
}
}
}
It's just an idea. You can optimize it and make it better. ;)