 # Resizing a mc depending on _y position?

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%.

``````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… ``````minY = 100;
maxY = 500;

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

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

I hope =]

If you’re using this random motion tutorial 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:

``````	//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.

Ooops, didn’t see this had been replied to…still, one of them should work Now I see mine wouldnt work well… should be
dancer._xscale = dancer._yscale = minScale + ( ( ( dancer._y - minY ) * ( maxY - minY ) ) / scaleRange );