A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: AS3 Tweening

  1. #1
    Member
    Join Date
    Jun 2007
    Posts
    39

    AS3 Tweening

    This might sound like a stupid question.

    But just how do I use AS3 tweening to get a normal movieclip to just get bigger?
    I basicly want to scale it up.

    myTween = new Tween(submenu_mc, "alpha",Regular.easeOut,0,1,12,false);

    This would be a simple turn on alpha tween, and so what I need to change is the "alpha" and maybe the Regualr.easeOut Im not sure, what I really would want is an easy help on the simple tweening that you can do, Ive been trying to read the API but I don't understand it very well.

    http://livedocs.adobe.com/flash/9.0/...riptLangRefV3/

    But when I just want something simple I can't seem to find it like what kind of attributes that can be tweened etc.
    Would I have to create 2 tweens one for x and one for y? or is there a simple "scale" attribute?

  2. #2
    Member
    Join Date
    Jun 2007
    Posts
    39
    Ok, looking about more in the API I found the attributes of a movieclip, but I still have to make 2x tweens one for scaleX and one for scaleY, right? or is there another way?

    Im not sure how to scale them also, guess ill go for abit of trial and error but any help would be great!

    or maybe its the hieght and width I should change... testing :P
    Last edited by Zahmet; 07-24-2007 at 07:58 AM.

  3. #3
    will i ever get it?
    Join Date
    Feb 2004
    Posts
    707
    hi zahmet...you can do this without using the tween class. you could use a timer, with exactly what you said...a variable to track scaleX and another to track scaleY...when the mc gets to be where you want it, stop the timer.

  4. #4
    Member
    Join Date
    May 2007
    Posts
    35
    Code:
    var myScale:Number;
    var myTween:Tween
    
    myTween = new Tween(this, myScale, Regular.easeOut, 0, 1, 12, false);
    
    myTween.addEventListener(TweenEvent.MOTION_CHANGE, onMotionChanged);
    myTween.addEventListener(TweenEvent.MOTION_FINISH, onMotionFinished);
    
    function onMotionChanged(event:TweenEvent):void
    {
    	submenu_mc.scaleX = submenu_mc.scaleY = event.position;
    }
    
    function onMotionFinished(event:TweenEvent):void
    {
    	event.target.removeEventListener(TweenEvent.MOTION_CHANGE, onMotionChanged);
    	event.target.removeEventListener(TweenEvent.MOTION_FINISH, onMotionFinished);
    	event.target = null;
    }
    Make sure that the scope of myScale is large enough so that it does not get garbage collected during the tween (ie. give it class scope).
    Last edited by Martin Munoz; 07-24-2007 at 10:56 AM.

  5. #5
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    It's very simple even with a ease-out effect:
    PHP Code:
    import flash.events.*;
    var 
    mc:= new M();
    mc.100;
    mc.100;
    addChild (mc);
    mc.addEventListener (Event.ENTER_FRAME,activated);
    function 
    activated (e:Event)
    {
        
    e.target.scaleX e.target.scaleY +=5/e.target.width;
        if(
    e.target.scaleX >= 5)
        {
            
    e.target.removeEventListener(Event.ENTER_FRAME,activated);
        }

    - The right of the People to create Flash movies shall not be infringed. -

  6. #6
    Member
    Join Date
    Jun 2007
    Posts
    39
    Thanks for the code cancerinform, but could you explane it to a new guy like me?

    You first make a new mc called M?
    set its x and y to 100
    add it as a child?
    When we enter the frame, it will scale x to y and some width?

    sorry Im just confused.

    Also lets say I have a movieclip how could I use that AS to make it grow?

  7. #7
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Quote Originally Posted by Zahmet
    You first make a new mc called M?
    set its x and y to 100
    add it as a child?
    mc is your MovieClip. This is just an example. You can have a MovieClip on the timeline already.
    ENTER_FRAME is an event, which fires continously with the framerate of your movie. One could also use the Timer class here. Then e.target refers to your Movieclip, which you scale until a certain size, here 5. This gives you an ease-out effect: 5/e.target.width.
    - The right of the People to create Flash movies shall not be infringed. -

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