Groups | Blog | Home
all groups > flash actionscript > july 2005 >

flash actionscript : Resize with an ease effect


JeankeB
7/4/2005 12:00:00 AM
Rapha, the method is simple, first off you define your target size,

var targetWidth:Number = 200 //for example, this will make your clip size to
200

// then you define an onEnterFrame function, wich will do the resizeing

yourClip.onEnterFrame = function() {
var currentWidth:Number = this._width; //record the current width
var difference:Number = currentWidth - targetWidth; // calc the
difference to resize

// now you have all the info needed to resize with an ease
this._width += difference / 5 //you can change this number for ease-ing
effects

//best to add this clean-up code too
if (Math.abs(difference) < 1) {
delete this.onEnterFrame;
this._width = targetWidth;
}
}

hope this helps

PS. I'm a starting Macromedia Forum member, sorry for any inconvenience, or
code mistakes


Rapha-Y2
7/4/2005 12:00:00 AM
Thanx guys,,, I'll try this one...I'm not good with actionscript, but I'll try
it..For example,, I got 3 Buttons. and What function can I put into them to
load a movie.

And.. I have to put this action on the first frame of the timeline?

Really Thanx man..


Rapha-Y2
7/4/2005 12:00:00 AM
It doesn't work man...

I'm trying some things, but It doesn't work,,

Ok,

MaxVT103
7/4/2005 12:00:00 AM
I found the easiest way to do this is alot like how Jeankeb did it, I had to
use mine for an image background resize at work. What I did was get the target
width like they did, then found out how many frames I wanted it to be for the
whole shift. I then divided that number by the total frames - 1 of the change.
You then have it set the width of the movieclip each frame and divide it by
your interval which is the total frames -1. The last 2 frames you divide it by
1/2 your interval. the code would look something like this for how I did it.




//variable declaration
var target_x:Number;
var target_y:Number;
var x_interval:Number = 0;
var y_interval:Number = 0;
var shift_Length:Number;

//to find the shift intervals

//this will find your x_interval
if(this._width < target_x)
{
x_interval = +(target_x - this._width)/(shift_length - 1);
}
else if(this._width > target_x)
{
x_interval = -(this._width - target_x)/(shift_length - 1);
}
else
{
x_interval = 0;
}

//this will find your y_interval
if(this._height < target_y)
{
y_interval = +(target_y - this._height)/(shift_length - 1);
}
else if(this._height > target_y)
{
y_interval = -(this._height - target_y)/(shift_length - 1);
}
else
{
y_interval = 0;
}

//this will now change its size of the movieclip
var i:Number = 0;
for(i = 0; i <= shift_Lenght - 2; i++)
{
this._width += x_interval;
this._width += y_interval;
setInterval(200); //causes it to wait for 2/10 of a second so that you
can see the shift
}
this._width += x_interval/2; //by dividing the last 2 times it shifts by 2
you will create a small ease effect at the end.
this._width += y_interval/2;
setInterval(200); //same as above
this._width += x_interval/2;
this._width += y_interval/2;
setInterval(200);
//end of code




now this can be done as a function and you replace "this" with a string that
holds your target and you have it input all the data into it like you normally
would. This is just how I did it because I just made it in a movieclip. I'm
sure there are other ways of doing this, but I hope this helped
Rapha-Y2
7/4/2005 12:00:00 AM
Man,,,really thanx ...

Is it just put thsi action on the first frame?

kglad
7/4/2005 12:00:00 AM
you guys are making the easy part complicated. the color fade is complicated.
the resize is easy. for example, you can copy the code below the dotted lines
to add a reSizeF() method to all movieclips. to use just executed:

yourMC.reSizeF(new_width, new_height);

------------------------------------------------------------------------------
MovieClip.prototype.reSizeF = function(w, h) {
function resizeF2(mc) {
if (Math.abs(mc._width-mc.w)>1 || Math.abs(mc._height-mc.h)>1) {
mc._width = .5*(mc._width+mc.w);
mc._height = .5*(mc._height+mc.h);
} else {
clearInterval(mc.int);
}
updateAfterEvent();
}
this.w = w;
this.h = h;
clearInterval(this.int);
this.int = setInterval(resizeF2, 70, this);
};
Rapha-Y2
7/4/2005 12:00:00 AM
Wow man.....it works..thanx a lot....

If you saw the link I posted with the example...you realize that on that
movie,,first it resizes on width, than after it resizes on its height, it?s
not the same time...undestand?

Thanx man....
kglad
7/4/2005 12:00:00 AM
Rapha-Y2
7/4/2005 2:03:23 PM
Hello there, I'm trying hard to get a code that make the effect with a swf
file, like this: http://www.evb.com
each clicked link makes an movie to change on its size and color....

Really need this

Thanx to all....
kglad
7/4/2005 8:46:51 PM
Rapha-Y2
7/4/2005 9:11:12 PM
kglad
7/4/2005 11:43:15 PM
MovieClip.prototype.reSizeF = function(w, h) {
function resizeF2(mc) {
if (Math.abs(mc._width-mc.w)>1) {
mc._width = .5*(mc._width+mc.w);
} else if (Math.abs(mc._height-mc.h)>1) {
mc._height = .5*(mc._height+mc.h);
} else {
clearInterval(mc.int);
}
updateAfterEvent();
}
this.w = w;
this.h = h;
clearInterval(this.int);
this.int = setInterval(resizeF2, 70, this);
};
kglad
7/5/2005 12:00:00 AM
Rapha-Y2
7/5/2005 12:57:34 PM
ow man,,, really thanx ...You helped me alot...

AddThis Social Bookmark Button