Scaling a Box (Actionscript)

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 (when the numbers are clicked the main box transforms to fit the image)

Thanks in Advance.

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

ok,
bye
prathap

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.

you can do something like:



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.

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



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

http://www.kirupa.com/developer/mx/easing_mouseclick.htm

Easing. Simple, easy, fun.

Easing is a basic equation

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

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

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

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

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

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

bye,
prathap

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

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

Example with easing equation…