# Yet Another Hit-test Problem

**URL:** https://forum.kirupa.com/t/yet-another-hit-test-problem/58348
**Category:** Uncategorized
**Created:** [July 21, 2004, 6:11pm UTC](https://forum.kirupa.com/t/yet-another-hit-test-problem/58348 "2004-07-21T18:11:40Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![happy\_hour](https://avatars.discourse-cdn.com/v4/letter/h/a183cd/32.png) [@happy\_hour](https://forum.kirupa.com/u/happy_hour)
#### Post date: [July 21, 2004, 6:11pm UTC](https://forum.kirupa.com/t/yet-another-hit-test-problem/58348/1 "2004-07-21T18:11:40Z")

</div>

Hey guys,

Ok. I have a simple movement script within the “ball” movie clip. The coding is all over the place so i dont blame you if it looks confusing.

I have made a boarder around the screen which is named “wall”. Basicly i don’t want the ball to pass this wall and when it touches the wall i want it to stop. Nothing fancy like bouncing off it, just stop it moving.

Thanks in advance,

```
    Rob.
```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 21, 2004, 6:15pm UTC](https://forum.kirupa.com/t/yet-another-hit-test-problem/58348/2 "2004-07-21T18:15:24Z")

</div>

You’ll probably be wanting the file…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 21, 2004, 6:16pm UTC](https://forum.kirupa.com/t/yet-another-hit-test-problem/58348/3 "2004-07-21T18:16:27Z")

</div>

ok. for some reason it wont upload…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 21, 2004, 6:16pm UTC](https://forum.kirupa.com/t/yet-another-hit-test-problem/58348/4 "2004-07-21T18:16:35Z")

</div>

Try this:

```php
 
onClipEvent (enterFrame) {
	if (_root.walls.hitTest(getBounds(_root).xMax, _y, true)) {
		this._x -= 5;
	}
	if (_root.walls.hitTest(getBounds(_root).xMin, _y, true)) {
		this._x += 5;
	}
	if (_root.walls.hitTest(_x, getBounds(_root).yMin, true)) {
		this._y += 5;
	}
	if (_root.walls.hitTest(_x, getBounds(_root).yMax, true)) {
		this._y -= 5;
	}
}
 

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 21, 2004, 6:18pm UTC](https://forum.kirupa.com/t/yet-another-hit-test-problem/58348/5 "2004-07-21T18:18:39Z")

</div>

got it! heres the file:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 21, 2004, 6:19pm UTC](https://forum.kirupa.com/t/yet-another-hit-test-problem/58348/6 "2004-07-21T18:19:54Z")

</div>

Did the code work?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 21, 2004, 6:22pm UTC](https://forum.kirupa.com/t/yet-another-hit-test-problem/58348/7 "2004-07-21T18:22:32Z")

</div>

No, but now i got the file uploaded (see above post) you can try it yourself.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 21, 2004, 6:23pm UTC](https://forum.kirupa.com/t/yet-another-hit-test-problem/58348/8 "2004-07-21T18:23:16Z")

</div>

Cant try it. it isnt MX, sorry.

P.S. How do you attach fla files?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 21, 2004, 6:24pm UTC](https://forum.kirupa.com/t/yet-another-hit-test-problem/58348/9 "2004-07-21T18:24:10Z")

</div>

it should be.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 21, 2004, 6:26pm UTC](https://forum.kirupa.com/t/yet-another-hit-test-problem/58348/10 "2004-07-21T18:26:19Z")

</div>

a straight upload. should i zip it first?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 21, 2004, 6:27pm UTC](https://forum.kirupa.com/t/yet-another-hit-test-problem/58348/11 "2004-07-21T18:27:22Z")

</div>

Ok.

P.S. How do you upload a fla? sorry, im new at the attaching.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 21, 2004, 6:31pm UTC](https://forum.kirupa.com/t/yet-another-hit-test-problem/58348/12 "2004-07-21T18:31:34Z")

</div>

when you go to the post reply screen scroll down a little and you can click the big “manage attachments” button.

From there you can browse for the file, then “upload” using the button. Just close the window (using the button) and submit reply using the bottom button.

BTW here’s a zip file incase it makes a difference.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 21, 2004, 6:37pm UTC](https://forum.kirupa.com/t/yet-another-hit-test-problem/58348/13 "2004-07-21T18:37:09Z")

</div>

heres help:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 21, 2004, 6:38pm UTC](https://forum.kirupa.com/t/yet-another-hit-test-problem/58348/14 "2004-07-21T18:38:29Z")

</div>

Yay! It uploaded!

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 21, 2004, 6:45pm UTC](https://forum.kirupa.com/t/yet-another-hit-test-problem/58348/15 "2004-07-21T18:45:41Z")

</div>

thats all very well but that code wont work on mine.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 21, 2004, 6:46pm UTC](https://forum.kirupa.com/t/yet-another-hit-test-problem/58348/16 "2004-07-21T18:46:53Z")

</div>

Oh, thats the only hitTest code I know. Sorry ☹

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 22, 2004, 8:56am UTC](https://forum.kirupa.com/t/yet-another-hit-test-problem/58348/17 "2004-07-22T08:56:00Z")

</div>

ok. Thanks for your help.

Im thinking of redoing the code then i’ll see if it works.:-/

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 22, 2004, 10:46am UTC](https://forum.kirupa.com/t/yet-another-hit-test-problem/58348/18 "2004-07-22T10:46:51Z")

</div>

instead of using a movieclip, and hitTesting, have you tried just using the boundaries of the movie?

like:

this bit can go on frame 1

```auto
 
_root.mtop = 0
_root.mleft = 0
_root.mbottom = 200
_root.mright = 400

```

this bit can go on an mc (on root)

```auto

onClipEvent(EnterFrame) {
 if (this._y<_root.mtop) {
  this._y = _root.mtop
 } else if (this._y>_root.mbottom) {
  _this._y = _root.mbottom
 }
 if (this._x<_root.mleft) {
 this._x = _root.mleft
 } else if (this._x>_root.mright) {
  this._x = _root.mright
 }
}

```

As ever, I can’t test if this works, because I’m not at home, but it looks like it should do.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 22, 2004, 11:20am UTC](https://forum.kirupa.com/t/yet-another-hit-test-problem/58348/19 "2004-07-22T11:20:34Z")

</div>

It sort of works exept the movie is 200 x 200 so the ball can only move around the bottom corner. I tried chaning the \_root.mright values but im not sure how they work.

Its a nice idea and it definitly works but im hoping to create a small town in which a character can walk around. Thats why i have the different images on each key press (so the character apears to be walking in the direction moving). Im still drawing so i just used a basic ball with arrows.

I was wondering if i could insert the hittest into each keypress code.  
The current code (movement to the right):

```php
 if (Key.isDown(39)) {
  this._x += 5;
  gotoAndPlay(4);
 }

```

i want to combine 2 “if” conditions. In writting it would sound like. IF Key is pressed move in direction (using the x or y adding or subracting) and go to frame “?” (where the image of the ball is. 1 to 5). Then add the hit test. so IF “ball” touches “wall” stop by adding or subtracting 5 from x or y value.

In the case of moving right this value would be this.\_x -=5;

I think…

Im getting confused just trying to explain it. :puzzle:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 22, 2004, 11:46am UTC](https://forum.kirupa.com/t/yet-another-hit-test-problem/58348/20 "2004-07-22T11:46:13Z")

</div>

I have decided to scrap my coding because it was usless and use the code in the ball and wall .fla which seemed to work quite well. Thanks for your help guys. Have a look at this .fla

Try going throught the gaps at the top and bottom. Confused? So am I.
