PDA

View Full Version : [AS2] hittest help?


blloobb187
05-16-2011, 12:34 PM
basically i have a character thats one movie clip called 'player' and a square doorway thats another movie clip called 'house', all i want is for when the character touches that square to go to frame '3' but instead of going to frame three on the actual thing it goes to frame '3' INSIDE the characters movieclip,
here's what i have;

onClipEvent (enterFrame) {
if (_root.player.hitTest(_root.house)) {
gotoAndPlay(3);}}

Noct
05-16-2011, 01:23 PM
You always need to target your gotoAndPlay to a timeline; since you are not passing it a target here, it defaults to "this", and will fire on the scope of the onEnterFrame. Meaning, whatever symbol it is that you are placing this script on is the one that will be targeted.

Parent up to the one that you want, or set a variable at the root of your application to the timeline you wish to target, and call that from within this method.

blloobb187
05-16-2011, 01:44 PM
okay on my character i have

onClipEvent (enterFrame) {
if (_root.player, hitTest(_root.house)) {
levelValue = 1;
}}

and on the main framei have

stop();
if(levelValue = 1 ){
gotoAndPlay(3);}

but now it just goes straight to frame 3?

tacos
05-16-2011, 01:55 PM
if(levelValue = 1 ){...

An if statement takes 2 "==" not only 1...

With only 1, you're in fact assigning the value of 1 to levelValue...

Noct
05-16-2011, 02:10 PM
Not only that, but unless you have that evaluation in a repeating event, it is only going to fire once, when the file loads. I think you are overthinking this and going to end up putting unneeded stress on your resources.

Dump all your root calls, and just parent up to the timeline you want to control. If these clips (player, and house) are sitting directly on the main timeline, you just go one level up the chain to target the main timeline, then you can call house from there; also, if "player" is the clip you are placing this event on, you don't need to call it at all, just reference it with "this":

onClipEvent (enterFrame) {
if (this.hitTest(this._parent.house)) {
this._parent.gotoAndPlay(3);
}
}

blloobb187
05-16-2011, 02:55 PM
ahhhh i get it, that worked great, thanks:)