Scaling using as

Hey,

If I drew a rectangle on stage using the api drawing methods and say the box was 100x50 in size, what method could I use to increase the size of the box over a period of time so that it appears to grow in size, or indeed shrink in size.

I understand I could simply use a for loop and then increase the width and height accordingly but how would I set the size of the rectangle that I would like the scaling to stop at.

cheers

Any help would be great.

scale = function (instance, amount, endscale) {
	if (instance._xscale != endscale) {
		instance._xscale = instance._yscale += amount
		updateAfterEvent ()
	} else {
		clearInterval (scaleInterval)
	}
}

scaleInterval = setInterval (scale, milliseconds, instance, amount, endscale)

milliseconds number of milliseconds to wait between every execution
instance instance name of the movie clip to scale
amount percentage to scale the movie clip in each execution
endscale final xscale and yscale value

example:

if your movie clip instance name is rectangle. you want to increase its scale by 10% each second and the final scale is 200%

scaleInterval = setInterval (scale, 1000, rectangle, 10, 200)

hope it helps :slight_smile:

Careful with this because you won’t necessarily have instance._xscale == endscale at some point so it might not stop at all :slight_smile:

scale = function (instance, amount, endscale) {
	if (instance._xscale **<** endscale) {
		instance._xscale = instance._yscale += amount
		updateAfterEvent ()
	} else {
		clearInterval (scaleInterval)
	}
}

scaleInterval = setInterval (scale, milliseconds, instance, amount, endscale)

happy ?? =)

No: what if you want the clip to shrink? :beam: :beam:

you add a new variable to tell the function what to do :stuck_out_tongue: