Forum Topic: As2 Hittest And Gotoandstop

(118 views • 5 replies)

This topic is 1 page long.

<< < > >>
None

ShirkDeio

Reply To Post Reply & Quote

Posted at: 10/6/09 12:06 PM

ShirkDeio LIGHT LEVEL 16

Sign-Up: 03/29/07

Posts: 989

I'm having some problems with a hitTest in a project, so I've been experimenting and I've come up with some really strange results. I'm trying to use hitTest after changing the frame of a movieclip, but for some reason it doesn't work. I assumed it was because the graphics didn't update until the next frame, but when I was experimenting I found that it sometimes works and sometimes doesn't.

Here's the example I made. Here's the code that runs it:

block.gotoAndStop(2);

btn1.onRelease = function() {
	block.gotoAndStop(1);
	txt.htmlText = "_xmouse,_ymouse: " + block.hitTest(_xmouse,_ymouse,true) + "<br />btn1: " + block.hitTest(this);
};
btn2.onRelease = function() {
	block.gotoAndStop(2);
	txt.htmlText = "_xmouse,_ymouse: " + block.hitTest(_xmouse,_ymouse,true) + "<br />btn2: " + block.hitTest(this);
};
btn3.onRelease = function() {
	block.gotoAndStop(3);
	txt.htmlText = "_xmouse,_ymouse: " + block.hitTest(_xmouse,_ymouse,true) + "<br />btn3: " + block.hitTest(this);
};

Click a white box to move the red box (via gotoAndStop) and the text will display first a shapeflag hitTest using _xmouse and _ymouse, then on the second line a hitTest with the white box you clicked.

What I've come up with so far is the hitTest on the box itself always works, the shapeflag hitTest on the far left box always works (it's the red box's frame 1... maybe that changes things?) the shapeflag hitTest on the middle one sometimes works (only after clicking the far right box then the middle box?) and the final shapeflag hitTest doesn't work.

All three hitTests work if you click the place that the red box is already over.

I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)


None

ShirkDeio

Reply To Post Reply & Quote

Posted at: 10/6/09 12:08 PM

ShirkDeio LIGHT LEVEL 16

Sign-Up: 03/29/07

Posts: 989

Anyways, with this weird result, I want to know if there's a good alternative or fix for this so I can finish my project? It would be a pain to have to develop it differently, because the shapes I'm testing in my project aren't just squares, so I can't simply change the _x and _y values to make it work, and they aren't all uniform, so I can't just change the _rotation.

I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)


None

Yambanshee

Reply To Post Reply & Quote

Posted at: 10/6/09 12:11 PM

Yambanshee DARK LEVEL 11

Sign-Up: 10/05/08

Posts: 1,588

At 10/6/09 12:06 PM, ShirkDeio wrote: All three hitTests work if you click the place that the red box is already over.

Im only getting this with the box to the far right.

AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature

None

ShirkDeio

Reply To Post Reply & Quote

Posted at: 10/6/09 12:15 PM

ShirkDeio LIGHT LEVEL 16

Sign-Up: 03/29/07

Posts: 989

The first box always works.

The second box works if it's clicked after the third box, or if it's clicked while it's covered by the red block.

The third box only works if it's clicked while it's covered by the red box.

That's what I get consistently. If you can call it consistent -- that's one strange problem.

I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)


None

Yambanshee

Reply To Post Reply & Quote

Posted at: 10/6/09 12:22 PM

Yambanshee DARK LEVEL 11

Sign-Up: 10/05/08

Posts: 1,588

try this:

block.gotoAndStop(2);

btn1.onRelease = function() {
	block.gotoAndStop(1);
};
btn2.onRelease = function() {
	block.gotoAndStop(2);
};
btn3.onRelease = function() {
	block.gotoAndStop(3);
};
function onMouseUp () {
	txt.htmlText = "_xmouse,_ymouse: " + block.hitTest(_xmouse,_ymouse,true) + "<br />btn3: " + block.hitTest(this);
}

AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature

None

ShirkDeio

Reply To Post Reply & Quote

Posted at: 10/6/09 12:24 PM

ShirkDeio LIGHT LEVEL 16

Sign-Up: 03/29/07

Posts: 989

Duh. It works that way in the simple demo that uses _xmouse and _ymouse and is always going to have a mouseUp called because we're dealing with clicks. But in my project it's much more complicated, so I need to understand the basic problem, which is why flash is so inconsistent with the hitTesting after the gotoAndStop.

I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)


All times are Eastern Standard Time (GMT -5) | Current Time: 05:53 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!