AS Resize (_width)

Hey All,

Need some help with what is probably really easy.

I need a script which can animate an objects resize through AS.

I know that…

on (rollOver) {
_root.reBox._width = 100;
}
on (rollOut) {
_root.reBox._width = 50;
}

…will jump my MC “reBox” to 100px on rollover and to 50px on Rollout, but how do I get AS to animate the transition - basically a tween!

Any help would be greatly appreciated.

Thanks guys.

mecha


onClipEvent(enterFrame){
if(_root.reBox,_root._xmouse,_root._ymouse){
if(_root.reBox._width - 5 > 50){
_root.reBox._width -= 5
//you can change the speed using that variable
}
}

i haven’t tested it but it might work – oh and btw check out the hitTest function, much better than rollOut or rollOver or anything…

I added some easing to the tween :wink:

argh, voets beat me to it =)

haha, it’s almost the same thing as mine.

*Originally posted by mlkdesign *
**

if(_root.reBox,_root._xmouse,_root._ymouse){

**
That’s a suspicious line… =)

I gotta say!!! What a forum!

Thanks for helping me out guys, I really appreciate it and will show yall what I using the script for a little later on today.

mlkdesign : hitTest. Yeah ive heard of it, will have a look later, thanks.

Voetsjoeba : It works great thanks, but I have no idea how! I probably sound sooooo stupid, but am a little confused on “tarW”.

thoriphes : Perfect! Plus I understand how it works…hurray!

Just one more question though. Looking at the examples posted up by Voetsjoeba and thoriphes…which one is coded best. I dont want to start an argument, its just I hear so much about clean coding that I wanted to know which version is better coded.

Once again,

THANKS GUYS!!! :stuck_out_tongue:

mecha

Well, obviously since you understand Thors code and mine not, thors is better coded :stuck_out_tongue: Both of ours have their advantages. Thors keeps the button, but constantly changes _root.onEnterFrame. Mine doesn’t, but I changed the button to a movieclip. Although movieclips can be used as buttons. It’s up to you.
By the way, thors runs way smoother on my pc than mine. Is that just me or do you experience the same ? Note to self: set standard framerate higher. End note :stuck_out_tongue:

Oh, and tarW stands for targetWidth. It indicates the width that the box should ease to. The essential code is on the box itself.

*thoriphes ? did I just say thoriphes ? wasn’t it ithuriel ? --checks-- yeah, thoriphes. What happened to ithuriel ?

actually, it ran smoother because i uped the frame rate. you had it set to the default 12. most animations look best when the frame rate is higher than 24.

I didn’t change the behavior of reBox, because i didn’t know what you still wanted to do with it, so i went with giving _root an onEnterFrame. between voets’ and my code, they’re pretty much the same. as for cleanliness, voets is better. If you notice, I assign an onEnterFrame function for each button event, which really isn’t clean, in my opinion. I would’ve gone with changing a variable and sticking with a constant onEnterFrame similar to what voets did.

D’oh !! Oh man, just forgot to set the framerate higher :P:P:P:P I feel so stupid !