ForumsProgramming Forum[Need help] hittest only works once?

60 13508
Voidcrystal
offline
Voidcrystal
138 posts
Nomad

when i make thise script:

onEnterFrame = function(){
if(ss.hitTest(_root.c2)){
_root.ss._x = -49.4;
}
}

it only does go to cords -49.4 once! the next time it happens nothing, can you solve it abn :P? Or anyone else??

  • 60 Replies
Voidcrystal
offline
Voidcrystal
138 posts
Nomad

"when i make thise script" haha i said thise, i ment "this" lol

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

You are telling ss to go to a certain position, not to change positions, so unless ss is moving on its own, it will perform the hittest more than once, but it won't look any different.

If you are telling it to move on its own, unless "ss" is a variable for an object, you need to use _root.ss or something like that when referring to it in the if statement. And if you are using ss as a variable for an object, you shouldn't have "_root.ss" inside the if function.


And, in case that doesn't work, is this code in a class or on a movieclip or on a frame?

Voidcrystal
offline
Voidcrystal
138 posts
Nomad

I am doing it in a frame, but i want it to go to a certain position and it only does it once and i am moving the movie clip with the arrow keys (ss is a variable for a movie clip)

onEnterFrame = function(){
if(ss.hitTest(_root.c2)){
ss._x = -49.4;
}
}

does not do any better ^^

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

This probably won't make any difference whatsoever, but try using function onEnterFrame(){ instead of onEnterFrame = function(){
Are you sure this frame is "active" when you are trying the hittest a second time?

Voidcrystal
offline
Voidcrystal
138 posts
Nomad

As i thought a Syntax Error :S, does onEnterFrame(){ without a function even exist?

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

There's a function in front of it, look at my last post.

Voidcrystal
offline
Voidcrystal
138 posts
Nomad

ahh, i did not see that no error but the script only did it once again.

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

Are you sure everything is still on this frame when you are trying the hittest a second time? and you aren't changing what object "ss" is?

Voidcrystal
offline
Voidcrystal
138 posts
Nomad

yep same frame!

Voidcrystal
offline
Voidcrystal
138 posts
Nomad

This is wierd, this should work!

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

Strange...You sure nothing else is interfering with it in any way?

Voidcrystal
offline
Voidcrystal
138 posts
Nomad

Nope :/

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

I don't see anything wrong with that code then. Something is probably changing after ss hits c2 the first time that it preventing it from running the hittest the second time, like you changing a variable or something... Is there something before the hittest like
if(...){
if(ss.hitTest(_root.c2)){
ss._x = -49.4;
}
}

Voidcrystal
offline
Voidcrystal
138 posts
Nomad

Nope there is just that script in that frame!
But in the movieclip's frames there is some moving scripts, can that change?

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

Depends if the variable "ss" is the entire movieClip or just part of it that goes away when the frame is changed

Showing 1-15 of 60