dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: using TWEEN to scale

  1. #1
    Senior Member
    Join Date
    Jul 2007
    Posts
    243

    using TWEEN to scale

    just a quick one i am trying to enlarge a rectangle (box) using the Tween function in AS3 like so:

    PHP Code:
    tw = new Tween(box"x"Strong.easeOutbox.scaleX21true);
        
    tw.addEventListener(TweenEvent.MOTION_CHANGE_syncScale);
    function 
    _syncScale($e:TweenEvent):void{
        
    box.scaleX box.scaleY tw.position;

    however when you scale it like this or with the "width" it scales it on one side, where as i want it to scale from the centre (like how things scale if you just hold the shift key when scaling in Flash)

    but i cant figure out how.
    thanks
    Dan Hodkinson

  2. #2
    trace("AKA: Biro Barna");
    Join Date
    Oct 2007
    Location
    RO.Timişoara
    Posts
    1,403
    Maybe something like this:

    PHP Code:
    import fl.transitions.Tween;
    import fl.transitions.easing.*;

    var 
    toMouseX:Tween;
    var 
    toMouseY:Tween;

    var 
    initialState:int 1;
    var 
    finalState:int 2;

    stage.addEventListener(MouseEvent.MOUSE_DOWNonStagePress);

    function 
    onStagePress(event:MouseEvent):void
    {
        
    easingAnimation();
    }
    function 
    easingAnimation():void
    {
        
    this.toMouseX = new Tween(box"scaleX"None.easeNone
                                  
    this.initialStatethis.finalState.5true);
        
        
    this.toMouseY = new Tween(box"scaleY"None.easeNone
                                  
    this.initialStatethis.finalState.5true);
        
        
    this.initialState this.finalState;
        
    this.finalState++;

    You have to scale both X and Y if you want the object to fully scale.

    Hope it helped.



    | Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro |
    WebLog: http://blog.wisebisoft.com/ |
    | Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
    |
    Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/
    | By perseverance the snail reached the ark. |


  3. #3
    Senior Member
    Join Date
    Jul 2007
    Posts
    243
    thanks but with the scaleY i had that covered with:
    box.scaleX = box.scaleY = tw.position;
    which scales the x the same as the Y i believe.

    also the mthod you showed me still just scales it "down + right" as opposed to from the middle and scaling it globally (up, down, left, right at the same time)

    hope that makes a bit more sense.
    Dan

  4. #4
    trace("AKA: Biro Barna");
    Join Date
    Oct 2007
    Location
    RO.Timişoara
    Posts
    1,403
    Ok, then I know what you are doing wrong. Both in my example and yours, be sure that you have the registration point of your movie clip centered. If you have the registration point at the TOP_LEFT or somewhere else then it will scale the object from there.



    | Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro |
    WebLog: http://blog.wisebisoft.com/ |
    | Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
    |
    Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/
    | By perseverance the snail reached the ark. |


  5. #5
    Senior Member
    Join Date
    Jul 2007
    Posts
    243
    ok then would you happen to know the code for that at all Plenary, after searching adobe i get this:
    The default registration point is (0,0)

    but it doesnt mention anything about where to change it.
    thanks
    Dan

    edit: i think i have found a work around where i edit the movie clip of the box and move it into its centre point, but just wondering whether there is a better, cleaner version using code?
    Last edited by danhodkinson; 02-27-2008 at 04:41 PM.

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