# Distances between 2 objects inside 2 movie clips

**URL:** <https://forum.kirupa.com/t/distances-between-2-objects-inside-2-movie-clips/185472>\
**Category:** flash\
**Created:** [April 13, 2006, 3:51pm UTC](https://forum.kirupa.com/t/distances-between-2-objects-inside-2-movie-clips/185472 "2006-04-13T15:51:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![leraptor](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/leraptor/32/2353_2.png) [@leraptor](https://forum.kirupa.com/u/leraptor)\
**Post date:** [April 13, 2006, 3:51pm UTC](https://forum.kirupa.com/t/distances-between-2-objects-inside-2-movie-clips/185472/1 "2006-04-13T15:51:52Z")

</div>

Hi guys,  
I know that I should use pythagore to calculate the distance, but I need to calculate distance between 2 objectfs that are contained within 2 different movie clips.  
Something in the line of :

xdist = Math.round(follow.p1.\_x - photo1\_mc.p1.\_x);  
ydist = Math.round(follow.p1.\_y - photo1\_mc.p1.\_y);  
distancefromthis = Math.round(Math.sqrt((xdist_xdist) + (ydist_ydist)));

But distancefromthis contains always the same value, maybe it’s because \_x is calculated within the movie clip, so I need to find the photo1.p1.\_x in the stage.  
Is it clear ?:pleased:  
Thanks !

---

<div class="post-metadata">

**Author:** ![joran420](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joran420/32/2329_2.png) [@joran420](https://forum.kirupa.com/u/joran420)\
**Post date:** [April 13, 2006, 4:07pm UTC](https://forum.kirupa.com/t/distances-between-2-objects-inside-2-movie-clips/185472/2 "2006-04-13T16:07:59Z")

</div>

> [@leraptor](#):
>
> Hi guys,  
> I know that I should use pythagore to calculate the distance, but I need to calculate distance between 2 objectfs that are contained within 2 different movie clips.  
> Something in the line of :
> 
> xdist = Math.round(follow.p1.\_x - photo1\_mc.p1.\_x);  
> ydist = Math.round(follow.p1.\_y - photo1\_mc.p1.\_y);  
> distancefromthis = Math.round(Math.sqrt((xdist_xdist) + (ydist_ydist)));
> 
> But distancefromthis contains always the same value, maybe it’s because \_x is calculated within the movie clip, so I need to find the photo1.p1.\_x in the stage.  
> Is it clear ?:pleased:  
> Thanks !

try

```auto

StageCoords1:Object = (x:follow.p1._x , y:follow.p1._y)
StageCoords2:Object = (x:photo1_mc.p1._x , y:photo1_mc.p1._y)
follow.localToGlobal(StageCoords1)
photo1_mc.localToGlobal(StageCoords2)

```

then find the distance between StageCoords1.(x or y) and StageCoords2

---

<div class="post-metadata">

**Author:** ![Mirandir](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Mirandir](https://forum.kirupa.com/u/Mirandir)\
**Post date:** [April 13, 2006, 4:09pm UTC](https://forum.kirupa.com/t/distances-between-2-objects-inside-2-movie-clips/185472/3 "2006-04-13T16:09:23Z")

</div>

You can use the movieclip method localToGlobal()

Here’s a simple example:

```auto

var p1 = {x:follow.p1._x, y:follow.p1._y};
var p2 = {x:photo1_mc.p1._x, y:photo1_mc.p1._y};

follow.localToGlobal(p1);
photo1_mc.localToGlobal(p2);

xdist = Math.round(p1.x - p2.x); 
ydist = Math.round(p1.y - p2.y); 

distancefromthis = Math.round(Math.sqrt((xdist*xdist) + (ydist*ydist))); 

```

/Mirandir

---

<div class="post-metadata">

**Author:** ![leraptor](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/leraptor/32/2353_2.png) [@leraptor](https://forum.kirupa.com/u/leraptor)\
**Post date:** [April 13, 2006, 4:13pm UTC](https://forum.kirupa.com/t/distances-between-2-objects-inside-2-movie-clips/185472/4 "2006-04-13T16:13:25Z")

</div>

YES !! This is perfectly working !  
Thanks Joran420 ! Thanks Mirandir !
