View Full Version : playing sound with hitTest
danulf
October 10th, 2004, 04:49 AM
is it possible? If yes, how?
I can't figure out how to make it work with attach sound, but that can have something to do with the fact that i'm pretty noobish :P
Dr Warm
October 10th, 2004, 05:03 AM
u can add a sound listener, u'll have to go to flash help to find out about this, i can't remember off the top of my head.
another method is to have the sound inside an empty mc. have the first frame empty with stop(); in the keyframe, then frame 2 have the sound
then on the hitTest with something:
if(hitTest <-- ur stuff){
//do something
_root.soundMc.gotoAndPlay(2);
}
that should work
danulf
October 10th, 2004, 08:48 AM
thank man! I'm gonna try it right now!
edit: the mc thing didn't work, and I can't find sound listener in the help. :sleep:
Dr Warm
October 10th, 2004, 09:10 AM
the mc should have worked, in the second frame did u put in the sound file, and then make some more frames until u can see the whole of the sound (i mean the whole of the zig zaggy blue lines) also i just noticed on actionscript.com someone posted the exact same thing:
_root.mySound = new Sound()
_root.mySound.attachSound("mySoundLinkageName")
myButton.onEnterFrame = function() {
if (this.hittest(_xmouse, _ymouse, true)) {
_root.mySound.Start()
}
} so maybe try that
danulf
October 10th, 2004, 11:17 AM
if (this.hittest(_xmouse, _ymouse, true) {
can I replace that code with:
if (ball.hitTest(top)) { ?
because I can't get it to work! I'm gonna check again, I must have done something wrong.
Dr Warm
October 10th, 2004, 10:20 PM
um did u try and test it with the hitTest for the mouse, cos at least u could have checked if it worked.
under where u have if (ball.hitTest(top)) { put trace("hitTest worked"); or something to see if ur hitTest is the problem.
if the hitTest is working, have u got the sound object in the library? And have u given it a linkage name, u have to tick the export for actionscript then put in like boom or something. then put this name in <code>_root.mySound.attachSound("mySoundLinkageName"); replacing </code><code>mySoundLinkageName with whatever u called the sound
</code>
Dr Warm
October 10th, 2004, 10:30 PM
hmm also there's a missing closing bracket in the code i put down (i was just testing u)
<code>if (this.hittest(_xmouse, _ymouse, true) should be:
</code><code>if (this.hittest(_xmouse, _ymouse, true)) but u probably would have chnaged it anyway</code>
danulf
October 11th, 2004, 10:36 AM
done all that, but I suck at actionscript, so I'm gonna try again! I really apreaciate (how do you spell it) your patience with me :rabbit:
Dr Warm
October 12th, 2004, 03:24 AM
That's okay i'm just repaying my debt to the flash community for helping me when i didn't know a variable from a something similiar (crap analogy i know)! If u still can't get it i'll make a fla that shows it (i hope), unforntunately sound hasn't been a big focus for me yet in flash, mainly cos i can't produce sounds myself.
danulf
October 12th, 2004, 12:38 PM
ok, made a test fla. I have no idea if I even have done what you suggested, but I think I did (-:. I gotta learn more about actionscript :}
Dr Warm
October 13th, 2004, 06:05 AM
ok here u go, u had a few errors in ur script and i fixed them, i hope u can see the difference between what i did and ur old script
keep at it man, and u'll do fine
at least your doing enough to make mistakes and having a go
danulf
October 13th, 2004, 10:23 AM
you're the BEST man! :rambo: Thank you very much.
I think I know what I did wrong now, I told the sound to play with a button right? Or did I get that wrong too? :azn:
Anyway, thanks alot man!
Dr Warm
October 14th, 2004, 04:00 AM
well the first problem was u had a hitTest inside a hitTest that were hitTesting the same thing (very bad don't do this).
And yeah the second one was u had a button something but u didn't actually have any buttons!
danulf
October 14th, 2004, 08:05 AM
Yeah, when i was comparing yours to mine, i saw alot of strange things in mine :nerd:, so ones again, thank you mate!
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.