Grow/Shrink Circle with AS
Below is what i have, i can get it to grow but not shrink... heh.. anyways I don't use AS usually when developing websites so i'm a complete beginner
The AS is on a a frame in the timeline and the mc is on a layer/ frame below it that extends for about 30 frames
thanks for any assistance
Code:
import flash.display.MovieClip;
import fl.transitions.Tween;
import fl.motion.Tweenables;
import fl.transitions.easing.Strong;
import fl.transitions.easing.None;
import fl.transitions.TweenEvent;
var tweenScaleX : Tween;
var tweenScaleY : Tween;
function grow(mc : MovieClip) : void
{
tweenScaleX = new Tween(mc, Tweenables.SCALE_X, None.easeNone, mc.scaleX, 2, .2, true);
tweenScaleY = new Tween(mc, Tweenables.SCALE_Y, None.easeNone, mc.scaleY, 2, .2, true);
tweenScaleX.addEventListener(TweenEvent.MOTION_FINISH, shrink);
}
grow(myCircle);
Moderator
I see that you have:
Actionscript Code:
tweenScaleX.addEventListener ( TweenEvent.MOTION_FINISH , shrink) ;
Did you define the shrink function?
It should have the tweenScaleX and tweenScaleY inside of it with the values for the size reveresed.
yea i defined the shrink function, not sure if it's correct though
Code:
import flash.display.MovieClip;
import fl.transitions.Tween;
import fl.motion.Tweenables;
import fl.transitions.easing.Strong;
import fl.transitions.easing.None;
import fl.transitions.TweenEvent;
var tweenScaleX : Tween;
var tweenScaleY : Tween;
function grow(mc : MovieClip) : void
{
tweenScaleX = new Tween(mc, Tweenables.SCALE_X, None.easeNone, mc.scaleX, 2, .2, true);
tweenScaleY = new Tween(mc, Tweenables.SCALE_Y, None.easeNone, mc.scaleY, 2, .2, true);
tweenScaleX.addEventListener(TweenEvent.MOTION_FINISH, shrink);
}
function shrink (mc : MovieClip): void
{
tweenScaleX = new Tween(mc, Tweenables.SCALE_X, None.easeNone, mc.scaleX, 0, .2, true);
tweenScaleY = new Tween(mc, Tweenables.SCALE_Y, None.easeNone, mc.scaleY, 0, .2, true);
}
grow(myCircle);
the problem I had when I ran your code is that when you ran the function grow(myCircle), you were passing the movie clip of myCircle to the function.
However when, on
tweenScaleX.addEventListener(TweenEvent.MOTION_FIN ISH, shrink);
you are just asking the function shrink to run, but the function itself is expecting you to pass it a movie clip. I don't think that you can pass something to an event triggered function. I was getting errors.
(If you can, I'd like to know).
So a compromise would be to have the event function trigger your shrink function passing it the movie clip you want. For example:
Actionscript Code:
import flash.display .MovieClip ;import fl.transitions .Tween ;import fl.motion .Tweenables ;import fl.transitions .easing .Strong ;import fl.transitions .easing .None ;import fl.transitions .TweenEvent ;var tweenScaleX : Tween;var tweenScaleY : Tween;function grow( mc : MovieClip ) : void { tweenScaleX = new Tween( mc, Tweenables.SCALE_X , None.easeNone , mc.scaleX , 2 , .2 , true ) ; tweenScaleY = new Tween( mc, Tweenables.SCALE_Y , None.easeNone , mc.scaleY , 2 , .2 , true ) ; tweenScaleX.addEventListener ( TweenEvent.MOTION_FINISH , runShrink) ;} function runShrink ( event:Event) :void { shrink( myCircle) ;} function shrink ( mc : MovieClip ) : void { tweenScaleX = new Tween( mc, Tweenables.SCALE_X , None.easeNone , mc.scaleX , .5 , .2 , true ) ; tweenScaleY = new Tween( mc, Tweenables.SCALE_Y , None.easeNone , mc.scaleY , .5 , .2 , true ) ; } grow( myCircle) ;
oh, and i changed it from 0 to .5 so you could still see the circle once it shrank
How to control the growing and shrinking with a mouse click
i am really impress by this code but is there any way to edit it so the growing and shrinking of the circle is controled by a mouse click?
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width