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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ActionScript Question (difficult)

Status
Not open for further replies.

MrKovacic

IS-IT--Management
Nov 5, 2002
213
US
Hi, I am working on a game, and i am using HitTest. BTW, I am using Flash 5. The code I am using lets me use the HitTest just fine, but on only one instance of the object.. Here is my code...

}
onClipEvent (enterFrame) {
if (_root.car.hitTest(_root.red)) {
_x = _x+10;
}
}
onClipEvent (enterFrame) {
if (_root.car.hitTest(_root.blue)) {
_y = _y+10;
}
}
onClipEvent (enterFrame) {
if (_root.car.hitTest(_root.yellow)) {
_x = _x-10;
}
}
onClipEvent (enterFrame) {
if (_root.car.hitTest(_root.green)) {
_y = _y-10;
}
}

The car is supposed to stop (or bounce) when it hits an instance of each color wall, and that works fine. But if I have 2 instances of red, it only works on the first one I made. Let me know if you need an example, but if I post one, it will be on my forum and I know advertising forums is not aloud.

Thank you in advance! :)
 
i think every mc needs its own name, i dont think you can have multiple instances of _root.red, you could try putting all the red walls in one big mc called _root.red

I learned a bit yesterday, today i learned a lot, imagine what i'll learn tomorrow!
 
Maybe you could rename the clips red1, red2, red3 etc and check them in a loop. I'd also strip out the enterFrame statements so it's a bit leaner like this:

onClipEvent (enterFrame) {
if (_root.car.hitTest(_root.red)) {
_x = _x+10;
} else if (_root.car.hitTest(_root.blue)) {
_y = _y+10;
} else if (_root.car.hitTest(_root.yellow)) {
_x = _x-10;
} else if (_root.car.hitTest(_root.green)) {
_y = _y-10;
}
}
 
Or you may try naming both instances differently, i.e. _root.red1 & _root.red2 and add a check for both in you enterFrame event.



Regards,

cubalibre2.gif
 
It worked, I just made more instances for each item... Thanx!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top