Hittest inside of a movieclip

Started by: Wsheerio | Replies: 4 | Views: 868

Wsheerio

Posts: 284
Joined: Nov 2009
Rep: 10

View Profile
Feb 26, 2010 6:48 AM #551111
I am trying to create a hittest inside of a movieclip and it doesn't work, can anyone tell me a solution and explain why this occurs.

Here is the code.
I've used this code outside of a movieclip and it worked.

onClipEvent (enterFrame) {
this._x -= 3;
if (this.hitTest(_root.Timer_End) == true) {
this._x += 3;
}
}

I thank you in advance.

Also, I know how to make a normal timer so don't explain that to me, I wanted to create a graphic one for this test.
Bonk
2

Posts: 2,778
Joined: Mar 2008
Rep: 10

View Profile
Feb 26, 2010 7:22 AM #551120
"this" refers to the movieclip the the object is in, not the object itself (it refers to the _parent object rather the nestled one). While I haven't coded in ages, you might be able to solve this by changing all the

this.

to

_parent.this.


While the above may not work, the reason you have this problem is due to referencing problems. If you don't mind giving your object inside the movieclip and instance name like "hit_object" or something, then you could use


_parent.hit_object.
Wsheerio

Posts: 284
Joined: Nov 2009
Rep: 10

View Profile
Feb 26, 2010 12:32 PM #551158
I've tried your solution with no luck, I would like to thank you for explaining my problem to me.
Scorpioxxx
2

Posts: 1,454
Joined: Apr 2006
Rep: 10

View Profile
Feb 26, 2010 2:14 PM #551173
"_root.parent instance name.child instance name" if you want to refer a MovieClip within another MovieClip.

Bonk is perfectly right the way I read it. "this." refers to the clip the script is in, nothing inside it specifically just everything that is.makes up the clip, ie, the clip selected when you were typing in the AS box it what it will apply to.
Wsheerio

Posts: 284
Joined: Nov 2009
Rep: 10

View Profile
Feb 26, 2010 9:13 PM #551238
Oh, I read the post incorrectly... lol, thank you all.