# Bounce effect script

**URL:** <https://forum.kirupa.com/t/bounce-effect-script/142942>\
**Category:** Uncategorized\
**Created:** [April 1, 2005, 5:40pm UTC](https://forum.kirupa.com/t/bounce-effect-script/142942 "2005-04-01T17:40:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Exedus](https://avatars.discourse-cdn.com/v4/letter/e/b19c9b/32.png) [@Exedus](https://forum.kirupa.com/u/Exedus)\
**Post date:** [April 1, 2005, 5:40pm UTC](https://forum.kirupa.com/t/bounce-effect-script/142942/1 "2005-04-01T17:40:55Z")

</div>

This script is for creating a resizing bounce effect on a button press. I hav one box I’m using this for. I’m wondering if there is any way I could manipulate the script so that I could have multiple boxes using this script at once? Here is the AS.

```auto

//for box 1
// Set initial variables
stageWidth=800; // Can also use the Stage.width property
stageHeight=600; // Can also use the Stage.height property
wmodifier = 225;
hmodifier = 271;
/* .7 for decent bounce effect */
bouncefactor = .7;
/* 6 for nice speed */
speedfactor = 8;
expand = function (id) {
	// colorSquare width
	this.destwidth = wmodifier;
	this.poswidth = id._width;
	this.velwidth = this.velwidth*bouncefactor+(this.destwidth-this.poswidth)/speedfactor;
	id._width += Math.round(this.velwidth);
	// colorSquare height
	this.destheight = hmodifier;
	this.posheight = id._height;
	this.velheight = this.velheight*bouncefactor+(this.destheight-this.posheight)/speedfactor;
	id._height += Math.round(this.velheight);
	// colorSquare x 
	this.destx = (stageWidth-wmodifier)/6; //starting position of the box
	this.posx = id._x;
	this.velx = this.velx*bouncefactor+(this.destx-this.posx)/speedfactor;
	id._x += Math.round(this.velx);
	// colorSquare y
	this.desty = (stageHeight-hmodifier)/2;
	this.posy = id._y;
	this.vely = this.vely*bouncefactor+(this.desty-this.posy)/speedfactor;
	id._y += Math.round(this.vely);
	// shadow properties
	shadow._width = (colorSquare._width+20);
	shadow._x = (colorSquare._x-10);
	shadow._height = (colorSquare._height+20);
	shadow._y = (colorSquare._y-10);
};
colorSquare.onEnterFrame = function() {
	expand(this);
};

```
