Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hit Test!!! helpp 1

Status
Not open for further replies.

PakiSensation

Programmer
Feb 15, 2002
2
0
0
US
HI guys..
nobody seemed to have an answer to this last night..
i have a square moving from one end of the stage to another..i have six buttons arranged at the bottom which can be dragged..now everytime u drag the button infront of the moving sqaure, i want a sound to be triggered..the square should detect the button with hitTest, play the sound and pass over it continuing on its path..in this way i wanna mix a few sounds as the square passes over each sound in its way...

code for sqaure MC:::

onClipEvent (enterFrame) {
if (this.hitTest(_root.buttonMC)) {
_root.XXXX}
}
IS There a function for playing a sound so that i can put that in place of XXX.
Please help me out..thanks
 
You can trigger sounds programatically by creating a Sound() object then referencing it from your code.

mySound=new Sound();
mySound.attachSound(soundEffect);
mySound.start();

Where soundEffect is a sound in your library set to be exported when the movie is published.
 
thanks..ill try tha..but can i enter the whole sound code as a result of the hitTest..meaning if the square touches the button, create sound and play it..and secondly will the square after hitting the button recognize it and move over it a the same time or not???
code:
onClipEvent (enterFrame) {
if (this.hitTest(_root.buttonMC)) {
mysound=new Sound();
mysound.attachSound(xx);
mysound.start();
}
}
 
or you could also just manipulate a remote movie clip with the sounds in it.

lets call this movieClip = soundMC
So when you have:

code for sqaure MC:::

onClipEvent (enterFrame) {
if (this.hitTest(_root.buttonMC)) {
_root.soundMC.gotoAndPlay("sound1")}
}

have the hitTest control the playhead of soundMC, and then place the sound in the correct frame so it plays the sound in soundMC and then stops.

defkon2012
 
faq250-756 may also help (item 7)

dave
dave@pinkzeppelin.com

^^^^^^^^^^^^^^^^^^^^^​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top