the if(this.hitTest(_root.SOMETHING)) istn working in my flash games.?

yofreke

New member
i have all the other codes right as well but the hit test isnt working right. it just wont recognize a collision between movie clips help please!
THIS refers to ant which is a movie clip
correction: SOMETHING refers to ant which is a movie clip
 
public function someFunction(){
if (object1.hitTestObject(object2)){
do something
}
}

you only refer to "this" if the hit test method exists inside the object class.

If you are using a document class, and you have instantiated both objects, just refer to their instances.

If there are more than one instances of each object, put them into an array, and refer to their position in the array, ie. object[1].

It would be easier to help you with this if I saw how your class structure was set up.

Edit: It seems like you are scripting in your timeline, instead of in a separate AS3 document.

This is going to be very problematic in a Flash gaming environment and make debugging a nightmare. You should assign a class to each movieclip, and control them through a dedicated class structure when developing something like a game.

Also, it looks like you are using AS2 and not AS3.

That said, if you are using timeline scripting, then use AS3 and drop the root garbage. Try

if {this.hitTestObject(parent.object2)}
 
public function someFunction(){
if (object1.hitTestObject(object2)){
do something
}
}

you only refer to "this" if the hit test method exists inside the object class.

If you are using a document class, and you have instantiated both objects, just refer to their instances.

If there are more than one instances of each object, put them into an array, and refer to their position in the array, ie. object[1].

It would be easier to help you with this if I saw how your class structure was set up.

Edit: It seems like you are scripting in your timeline, instead of in a separate AS3 document.

This is going to be very problematic in a Flash gaming environment and make debugging a nightmare. You should assign a class to each movieclip, and control them through a dedicated class structure when developing something like a game.

Also, it looks like you are using AS2 and not AS3.

That said, if you are using timeline scripting, then use AS3 and drop the root garbage. Try

if {this.hitTestObject(parent.object2)}
 
Back
Top