# Proximity

**URL:** <https://forum.kirupa.com/t/proximity/33792>\
**Category:** Uncategorized\
**Created:** [October 23, 2003, 6:07pm UTC](https://forum.kirupa.com/t/proximity/33792 "2003-10-23T18:07:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![shuga](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@shuga](https://forum.kirupa.com/u/shuga)\
**Post date:** [October 23, 2003, 6:07pm UTC](https://forum.kirupa.com/t/proximity/33792/1 "2003-10-23T18:07:07Z")

</div>

I wrote this action script to display the proximity of one object to another. The eventual idea is to use this as a variable in an interactive function, not just display it in a text box.

I seem to remember something that is already in flash that does this but I can’t remember what it is.

If there is a function that is already in flash that will detect this or a better (shorter) way to write this script, please let me know.

Here’s the script:

```php

onEnterFrame = function () {
	// create the function that will read the proximity of ball 2 to ball 1
	xDiff = Math.abs(_root.ball1._x-_root.ball2._x);
	yDiff = Math.abs(_root.ball1._y-_root.ball2._y);
	prox = xDiff+", "+yDiff;
	// set the text box to read the proximity of ball 2 to ball 1
	_root.coords.text = prox;
};

```

Thanks,
