# Resizing a mc depending on \_y position?

**URL:** <https://forum.kirupa.com/t/resizing-a-mc-depending-on--y-position/205008>\
**Category:** Uncategorized\
**Created:** [October 25, 2006, 10:33am UTC](https://forum.kirupa.com/t/resizing-a-mc-depending-on--y-position/205008 "2006-10-25T10:33:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![will2](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/will2/32/2815_2.png) [@will2](https://forum.kirupa.com/u/will2)\
**Post date:** [October 25, 2006, 10:33am UTC](https://forum.kirupa.com/t/resizing-a-mc-depending-on--y-position/205008/1 "2006-10-25T10:33:22Z")

</div>

I’ve used the random motion tutorial, and got that working. Now i’d like things to resize themselves depending on where they are on the screen… For example, if its at the very top, its 75% and if its at the bottom, 125%.

```auto
minsize = 75;
maxsize = 125;
dancerSize = _y;

if (bla bla bla, i got stuck at this point) {
    dancer._yscale = dancerSize;
    dancer._xscale = dancerSize;
}

```

Any help would be great… 😊

---

<div class="post-metadata">

**Author:** ![mathew\_er](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mathew\_er](https://forum.kirupa.com/u/mathew_er)\
**Post date:** [October 25, 2006, 12:45pm UTC](https://forum.kirupa.com/t/resizing-a-mc-depending-on--y-position/205008/2 "2006-10-25T12:45:44Z")

</div>

```auto
minY = 100;
maxY = 500;

minScale = 75;
maxScale = 125;
scaleRange = maxScale - minScale;

dancer._xscale = dancer._yscale = minScale + ( ( ( dancer._y - minY ) * maxY ) / scaleRange );

```

I hope =]

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [October 25, 2006, 12:50pm UTC](https://forum.kirupa.com/t/resizing-a-mc-depending-on--y-position/205008/3 "2006-10-25T12:50:04Z")

</div>

If you’re using this random motion tutorial [http://www.kirupa.com/developer/actionscript/random\_motion.htm](http://www.kirupa.com/developer/actionscript/random_motion.htm)  
then add these lines to the bottom of the OnClipEvent code attached to the movieclip dot:

```auto
	//y scale
	this._xscale = this._yscale=75+((this._y/Stage.height)*100)/2;

```

As you can see, this divides the .\_y value by the stage height and multiplies it by 100, thus giving you a percentage. The percentage is then divided by 2 and your minimum value of 75 is added. Finally, this new value is applied to both the .\_xscale and the .\_yscale of the movieclip to ensure that the scaling is constrained.

Some quick calculations demonstrate how the formula works:  
when this._y = 0, this_.yscale = 75 + ((0/200)\*100)/2 = 75 + 0 = 75  
when this._y = 100, this_.yscale = 75 + ((100/200)\*100)/2 = 75 + 25 = 100  
when this._y = 200, this_.yscale = 75 + ((200/200)\*100)/2 = 75 + 50 = 125

An amended version (Flash 8) is attached.

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [October 25, 2006, 12:51pm UTC](https://forum.kirupa.com/t/resizing-a-mc-depending-on--y-position/205008/4 "2006-10-25T12:51:08Z")

</div>

Ooops, didn’t see this had been replied to…still, one of them should work 😉

---

<div class="post-metadata">

**Author:** ![mathew\_er](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mathew\_er](https://forum.kirupa.com/u/mathew_er)\
**Post date:** [October 25, 2006, 12:54pm UTC](https://forum.kirupa.com/t/resizing-a-mc-depending-on--y-position/205008/5 "2006-10-25T12:54:25Z")

</div>

Now I see mine wouldnt work well… should be  
dancer.\_xscale = dancer.\_yscale = minScale + ( ( ( dancer.\_y - minY ) \* **( maxY - minY )** ) / scaleRange );
