all groups > flash actionscript > december 2005 >
You're in the

flash actionscript

group:

Actionscript animation help


Actionscript animation help bubba_puck
12/28/2005 10:52:11 PM
flash actionscript:
I am trying to animate an object in actionscript and am having a little
trouble. Here is the scenario:

On the root timeline, there is a movie clip instance named main_mc. Inside of
main_mc I have an small object with an instance name of frameUL_mc (this is
positioned at X: 215 and Y: -45). When I roll over main_mc I want the
frameUL_mc object to move to postion X: 175 and Y: -5). I want to control
frameUL_mc from frame 1 of the main timeline and not actionscript on the movie
clip or motion tweening inside the frameUL_mc timeline. I would like to add
easing and a variable to control the speed but that is not as important as
getting the animation to work.

I did use the motion tween on the frameUL_mc timeline and used gotoAndPlay to
different states of the movie clip (using frame labels). But when I rolled off
then rolled back on too quick, the movie got all screwie on me.

Can anyone please help.

Thanks... Bubba
Re: Actionscript animation help kglad
12/28/2005 11:08:18 PM
moveI=setInterval(moveF,70);
function moveF(){
var mc=_root.main_mc.frameUL_mc;
mc._x=.5*(mc._x+175);
mc._y=.5*(mc._y-5);
if(Math.abs(mc._x-175)<1&&Math.abs(mc._y+5)<1){
clearInterval(moveI);
mc._x=175;
mc._y=-5;
}
}


Re: Actionscript animation help bnailWedge
12/28/2005 11:08:51 PM
Re: Actionscript animation help bubba_puck
12/28/2005 11:11:31 PM
I dont really have any current code. I am fairly familar with actionscript but
just wasnt sure what type of math formula would work to get the movement going
in both directions depending on roll over or rollout. I knew it would be
someway of changing the X/Y positioning but nothing I could come up with was
even close.
Re: Actionscript animation help kglad
12/28/2005 11:12:10 PM
or more generally:

speed=.95 // speed should be less than 1 and greater than zero

moveI=setInterval(moveF,70,speed);
function moveF(s){
var mc=_root.main_mc.frameUL_mc;
mc._x=s*mc._x+(1-s)*175;
mc._y=s*mc._y+(s-1)*5;
if(Math.abs(mc._x-175)<1&&Math.abs(mc._y+5)<1){
clearInterval(moveI);
mc._x=175;
mc._y=-5;
}
}
Re: Actionscript animation help bubba_puck
12/28/2005 11:17:35 PM
Thanks kglad. I am not quite sure what is happening but I can figure it out
myself when I get home from work. Will this work in both directions? When I
rollover the movie clip I want it to move in and when you roll off I want it to
move out.

Thanks though for the place to start I will try it out and let you know how it
goes.
Re: Actionscript animation help bnailWedge
12/28/2005 11:31:04 PM
I would recommend you try the tween class. I use it quite a bit for all kinds
of animation tasks. All easing and movement, scaling, rotation, etc..., can be
achieved with random/dynamic variables. Once you get past the tiny learning
curve, you will find it is very easy to use and manipulate.

http://www.macromedia.com/devnet/flash/articles/tweening.html
Re: Actionscript animation help kglad
12/29/2005 1:17:09 AM
no, that code wouldn't move your movieclip back again. the code can be edited,
though, to be more general and ease movieclip mc into targetX,targetY at a rate
set by speed:

moveI=setInterval(moveF,70,mc,speed,targetX,targetY);

function moveF(mc,s,x,y){
var mc=_root.main_mc.frameUL_mc;
mc._x=s*mc._x+(1-s)*x;
mc._y=s*mc._y+(s-1)*y;
if(Math.abs(mc._x-x)<1&&Math.abs(mc._y-y)<1){
clearInterval(moveI);
mc._x=x;
mc._y=y;
}
}
Re: Actionscript animation help bubba_puck
12/29/2005 1:38:47 AM
Guys, thanks so much for the help you have given!!!

Here is a link that may clear up what I am trying to accomplish:
http://www.online-discount-shopping.com/flash/testFrame2.html

. I can do this with tweening and using onRollOver to gotoAndPlay a different
frame but if I move off the button too fast, it screws the whole movie up.
Here is the code I currently have:
_root.main_mc.hit_mc.onRollOver = function() {
_root.main_mc.gotoAndPlay("fadeIn");
}

_root.main_mc.hit_mc.onRollOut = function() {
_root.main_mc.gotoAndPlay("fadeOut");
}

I am trying to now put all off the tweening into code on frame 1 to comply
with actionscript 2 principles and make the tween smoother but I cant get it to
work. The code showed above doesnt quite achieve what I need. Any help would be
greatly appreciated!

Thanks... EB
Re: Actionscript animation help kglad
12/29/2005 3:07:26 AM
Re: Actionscript animation help bnailWedge
12/29/2005 4:08:08 PM
Behold, the Tween class in action:



stop();
import mx.transitions.Tween; // Need to include to make the Tween Class work
import mx.transitions.easing.*; // Need to include to make the Easing work

function collapseOutline(){
scaleTo = 85; // Percentage to collapse the outline to.
moveTime = .5; // Amount of time it takes for the collapse - in seconds.
new Tween(outLines, "_yscale", Bounce.easeOut, outLines._yscale, scaleTo,
moveTime, true);
new Tween(outLines, "_xscale", Bounce.easeOut, outLines._xscale, scaleTo,
moveTime, true);
new Tween(outLines, "_alpha", Bounce.easeOut, outLines._alpha, 100, moveTime,
true);
};
function expandOutline(){
scaleTo = 100; // Percentage to expand the outline to.
moveTime = .5; // Amount of time it takes for the expand - in seconds.
new Tween(outLines, "_yscale", Bounce.easeOut, outLines._yscale, scaleTo,
moveTime, true);
new Tween(outLines, "_xscale", Bounce.easeOut, outLines._xscale, scaleTo,
moveTime, true);
new Tween(outLines, "_alpha", Bounce.easeOut, outLines._alpha, 0, moveTime,
true);
};
// Below is your code modified to work with my example.
_root.main_mc.onRollOver = function() {
collapseOutline();
}

_root.main_mc.onRollOut = function() {
expandOutline();
}
// End of your code here.
/*
These are the easing types you can use:

6 categories of movement:
Strong
Back
Elastic
Regular
Bounce
None

4 types of easing are:
easeIn
easeOut
easeInOut
easeNone

Put them together to make your movement. Examples below:
Bounce.easeOut
Bounce.easeIn
Regular.easeOut
Regular.easeIn
*/
Re: Actionscript animation help bnailWedge
12/29/2005 4:11:50 PM
AddThis Social Bookmark Button