A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Grow/Shrink Circle with AS

  1. #1
    Junior Member
    Join Date
    Jan 2008
    Posts
    3

    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);

  2. #2
    Moderator enpstudios's Avatar
    Join Date
    Jun 2001
    Location
    Tampa, Fl.
    Posts
    11,282
    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.

  3. #3
    Junior Member
    Join Date
    Jan 2008
    Posts
    3
    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);

  4. #4
    Member
    Join Date
    Jul 2009
    Posts
    88
    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

  5. #5
    Registered User
    Join Date
    Feb 2013
    Posts
    1

    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center