# Calculating distance witin a movieclip that moves

**URL:** <https://forum.kirupa.com/t/calculating-distance-witin-a-movieclip-that-moves/209438>\
**Category:** Uncategorized\
**Created:** [December 8, 2006, 8:30pm UTC](https://forum.kirupa.com/t/calculating-distance-witin-a-movieclip-that-moves/209438 "2006-12-08T20:30:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chaoti](https://avatars.discourse-cdn.com/v4/letter/c/e47c2d/32.png) [@chaoti](https://forum.kirupa.com/u/chaoti)\
**Post date:** [December 8, 2006, 8:30pm UTC](https://forum.kirupa.com/t/calculating-distance-witin-a-movieclip-that-moves/209438/1 "2006-12-08T20:30:12Z")

</div>

I am trying to modify this code that is attached to and alpha engine. It is the same code from the tutorial: Calculating Distance

onClipEvent (enterFrame) {  
xdist = Math.round(\_root.\_xmouse - \_parent.\_x);  
ydist = Math.round(\_root.\_ymouse - \_parent.\_y);  
distancefromthis = Math.round(Math.sqrt((xdist_xdist) + (ydist_ydist)));  
\_parent.\_alpha = (100-distancefromthis)+20;  
}

What i need to know is whether or not i can modify this to calculate the distance of the mouse from the clip, even if it is contained in another clip that moves around the stage.

Any suggestions?
