# Scaling a Box (Actionscript)

**URL:** https://forum.kirupa.com/t/scaling-a-box-actionscript/14903
**Category:** flash
**Created:** [March 4, 2003, 6:34am UTC](https://forum.kirupa.com/t/scaling-a-box-actionscript/14903 "2003-03-04T06:34:47Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![imark](https://avatars.discourse-cdn.com/v4/letter/i/c5a1d2/32.png) [@imark](https://forum.kirupa.com/u/imark)
#### Post date: [March 4, 2003, 6:34am UTC](https://forum.kirupa.com/t/scaling-a-box-actionscript/14903/1 "2003-03-04T06:34:47Z")

</div>

Basically I’m looking for a tutorial to scale a “box” on the click of a button. For **example** my “box” is first 100x200, and when a button is clicked the box transforms (smootly) to 50x300.

Here’s a visual of what im looking for: [http://www.stefanbuechner.com/index.html](http://www.stefanbuechner.com/index.html) (when the numbers are clicked the main box transforms to fit the image)

Thanks in Advance.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 4, 2003, 2:12pm UTC](https://forum.kirupa.com/t/scaling-a-box-actionscript/14903/2 "2003-03-04T14:12:03Z")

</div>

hai i am prathap,

I can solve your problem, very cool one,

I will make one box and make it a movie a clip, I will give the instance name as box, Now it’s size is 800/600.

I hope till here it is clear.

Now make one more button,

give the actionscript like below,

on(release)  
{  
\_root.box.\_xscale=400;  
\_root.box.\_yscale=200;  
}

this will work,

if it dosn’t work mail me to [bsprathapsimha@rediffmail.com](mailto:bsprathapsimha@rediffmail.com)

ok,  
bye  
prathap

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 5, 2003, 4:37am UTC](https://forum.kirupa.com/t/scaling-a-box-actionscript/14903/3 "2003-03-05T04:37:11Z")

</div>

Thanks Prathap, the action script works fine. But now I want to have the box scale smoothly (like with motion), not just change size.

Thanks again.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 5, 2003, 4:47am UTC](https://forum.kirupa.com/t/scaling-a-box-actionscript/14903/4 "2003-03-05T04:47:47Z")

</div>

you can do something like:

```php

on(release)
{
for (x = 0, x < 10, x++)
{
_root.box._xscale = _root.box._xscale + 30
_root.box._yscale = _root.box._yscale + 10
}
}

```

what determines the 30 and the 10? well, you want to go from 100 scale to 400 scale, and from 100 scale to 200 scale… right? The for loop is going to have 10 intervals, so you have to divide the differences between the scales by the number of intervals… (400 - 100)/10 = 30… etc.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 5, 2003, 4:59am UTC](https://forum.kirupa.com/t/scaling-a-box-actionscript/14903/5 "2003-03-05T04:59:28Z")

</div>

> \*Originally posted by lavaboy \*  
> \*\*you can do something like:

```php

on(release)
{
for (x = 0, x < 10, x++)
{
_root.box._xscale = _root.box._xscale + 30
_root.box._yscale = _root.box._yscale + 10
}
}

```

what determines the 30 and the 10? well, you want to go from 100 scale to 400 scale, and from 100 scale to 200 scale… right? The for loop is going to have 10 intervals, so you have to divide the differences between the scales by the number of intervals… (400 - 100)/10 = 30… etc. \*\*

hrmm this one didnt work

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 5, 2003, 5:30am UTC](https://forum.kirupa.com/t/scaling-a-box-actionscript/14903/6 "2003-03-05T05:30:31Z")

</div>

[http://www.kirupa.com/developer/mx/easing\_mouseclick.htm](http://www.kirupa.com/developer/mx/easing_mouseclick.htm)

Easing. Simple, easy, fun.

Easing is a basic equation

```php
_x += (endX-_x)/speed;
	_y += (endY-_y)/speed;

```

Yep… of course, these use coordinates. So instead of using \_x and \_y stuff just use \_xscale and \_yscale stuff.

THe effect is still the same, it just resizes. The important part is that endX and endY equal your final detination, whether it be size or coordinates.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 5, 2003, 5:34am UTC](https://forum.kirupa.com/t/scaling-a-box-actionscript/14903/7 "2003-03-05T05:34:35Z")

</div>

well… the problem with mine is that it’s not going to animate… (by the way, the commas in the for loop are supposed to be semicolons…) both lost and I are right… but you want it to animate, right? you should use an onEnterFrame function… something like

```php
box.onEnterFrame = function(){
//insert here code that lost put in..
}

```

and you would call that function from the on(release) handler

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 5, 2003, 5:36am UTC](https://forum.kirupa.com/t/scaling-a-box-actionscript/14903/8 "2003-03-05T05:36:13Z")

</div>

If you read the tutorial I posted above you would see my method animates too 😉

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 5, 2003, 5:37am UTC](https://forum.kirupa.com/t/scaling-a-box-actionscript/14903/9 "2003-03-05T05:37:27Z")

</div>

hai,

I got your question, Some people replied for your problem. Those scripts work fine and its good. But it can be done in much more simpler way, I am sending you one fla and I also responded to your personnal mail id.

Download this FLA

Further questions, mail me to [bsprathapsimha@rediffmail.com](mailto:bsprathapsimha@rediffmail.com)

bye,  
prathap

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 5, 2003, 5:37am UTC](https://forum.kirupa.com/t/scaling-a-box-actionscript/14903/10 "2003-03-05T05:37:58Z")

</div>

haha… I should have read that tut a while ago…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 5, 2003, 5:42am UTC](https://forum.kirupa.com/t/scaling-a-box-actionscript/14903/11 "2003-03-05T05:42:42Z")

</div>

That doesn’t ease in like the example show though bsprat.

Example with easing equation…

> **[Save BIG with $9.99 .COMs from GoDaddy!](http://www.lostinbeta.com/WQVQZ/experimental/imageResizer.html)**
>
> Get your own corner of the Web for less! Register a new .COM for just $9.99 for the first year and get everything you need to make your mark online — website builder, hosting, email, and more.
