# Get a random point on stage

**URL:** <https://forum.kirupa.com/t/get-a-random-point-on-stage/260887>\
**Category:** Uncategorized\
**Created:** [May 20, 2008, 7:05pm UTC](https://forum.kirupa.com/t/get-a-random-point-on-stage/260887 "2008-05-20T19:05:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jansensan](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jansensan/32/3362_2.png) [@jansensan](https://forum.kirupa.com/u/jansensan)\
**Post date:** [May 20, 2008, 7:05pm UTC](https://forum.kirupa.com/t/get-a-random-point-on-stage/260887/1 "2008-05-20T19:05:49Z")

</div>

hello all, i am trying to do somthing super simple but i just cant wrap my head around it.

i have a movieclip that is in the shape of a tree.

i need to get a random point on the tree. so i first get a random point on the stage, then i check if that point is over the tree (with hitTestPoint)

if it is then i return the point since i need the x and y coordinates to do something.

if not i need to get another point.

my problem is that i cant figure out how to get another one if my point is not valid. i did something like:

```auto
var point:Point = new Point ((Math.random () * _stageWidth), (Math.random () * _stageHeight));

if (_treeArea.hitTestPoint (point.x, point.y, true)) {
     return point;

    } else {
    // how do i get another one and redo the previous steps? i miss basic's GOTO LINE :(
}

```

maybe something recursive should be done? how?

---

<div class="post-metadata">

**Author:** ![Felixz](https://avatars.discourse-cdn.com/v4/letter/f/ecb155/32.png) [@Felixz](https://forum.kirupa.com/u/Felixz)\
**Post date:** [May 20, 2008, 10:06pm UTC](https://forum.kirupa.com/t/get-a-random-point-on-stage/260887/2 "2008-05-20T22:06:40Z")

</div>

```auto
var point:Point = new Point ((Math.random () * _stageWidth), (Math.random () * _stageHeight));
while (_treeArea.hitTestPoint (point.x, point.y, true)) {
     return point;
}

```
