A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: easing effect problem

  1. #1

    easing effect problem

    Hi there, I doing an easing effect to scale a movieclip from the current size to a targeted size say 50pixel width. The problem is the number is always exceed the targeted size when it's moving, therefore i cant delete my onEnterFrame. anybody out there know the way to solve please let me know.

    function moveMe(){
    var boxHeight:Number=box_mc._height;
    var boxWidth:Number=box_mc._width;
    var speed:Number=5;
    box_mc._width+=(boxTargetWidth-boxWidth)/speed;
    boxWidth=box_mc._width;
    trace(boxWidth);
    if (boxWidth==boxTargetWidth){
    delete box_mc.onEnterFrame;
    }
    }

    thanks
    ks
    to me, design is a way of infusing life...

  2. #2
    Flash Student rabidlemming's Avatar
    Join Date
    Mar 2003
    Location
    UK
    Posts
    382
    Hi,

    Perhaps you can work out the difference and then minus the difference to run the check

    Code:
    function moveMe(){
    var boxHeight:Number=box_mc._height;
    var boxWidth:Number=box_mc._width;
    var speed:Number=5;
    box_mc._width+=(boxTargetWidth-boxWidth)/speed;
    boxWidth=box_mc._width;
    trace(boxWidth);
    var difference = boxWidth - boxTargetWidth
    if (boxWidth== difference){
    delete box_mc.onEnterFrame;
    }
    }
    I hope that helps

    Cheers
    Rabid Lemming

    I will wait for death with a smile and a big stick

  3. #3
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Try with...


    if (math.round(boxWidth)== math.round(difference)){

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  4. #4
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    reduce the ease each iteration, and it always goes. the basic idea is
    code:

    if (speed < 1) {
    speed=1;
    } else {
    speed=speed*.9;
    //or .99, or .5, there can be some heavy math involved but doesnt need to be



    that works with division as per your example. if you use multiplication instead, you can still usually use it but you may want to use straight decrementation (less a set amounch each iteration).

    the vast majority of flash animation that i've seen can really be broken down to
    code:

    targets._value += (destination_value - targets._value) / ease_rate;


    or *ease_rate and use a number less than 1.

    so you put those two together and you get something like this, using shorthand cos you really dont need to reference it or make many changes, and it saves lots of room in the actions panel (more than half, probably).
    code:

    //t = target, d=destination,r=rate of ease,p=property
    function animation(t, d, r, p) {
    t.onEnterFrame=function() {
    Math.round(this[p])==d?delete this.onEnterFrame:((this[p]+=(d-this[p])/r), (r<1?(r=1):r=r*.92));
    }
    }



    which is pretty straightforward - one line of script will handle pretty much all the 'stock' trans. course, there are other ways its all just pref. anyways, you'd call any property you want, like this
    code:

    this.your_mc.onPress=function() {
    animation(this, 0, 8, "_alpha");
    }
    //or
    this.buttonclip.onPress=function() {
    animation(some_other_mc, 400, 15, "_y");
    }


    hth, gl

    edit: my flash prog is dead at the moment so the above is untested, but should be ok - if not, just check curlies and parens for syntactical erros. sry :/
    Last edited by moagrius; 11-29-2004 at 09:24 AM.

  5. #5
    if (math.round(boxWidth)== math.round(difference)){

    the above code is still not working though. it works only when i put my speed (var speed:Number=2 it only works for 2, any other numbers will exceed the targeted width.

    thanks
    ks
    to me, design is a way of infusing life...

  6. #6
    Inspector General
    Join Date
    May 2001
    Posts
    493
    first moagrius' solution is super slick, i gotta start using that.

    second if
    code:

    if(boxWidth== boxTargetWidth){}



    is never true as you state. the dirty way would be something like this:

    code:

    if(boxWidth >= (boxTargetWidth-1)){
    box_mc._width=boxTargetWidth;
    delete box_mc.onEnterFrame;
    }



    pretty much this checks to see if the boxWidth is REALLY close to the boxTargetWidth, and if it is it will just bump it to the boxTargetWidth.

    i don't know how your easing is working visually so i don't know if this will cause a large visual shift. you may have to play around with how much you subtract from or add to the boxTargetWidth.

  7. #7
    Thanks for your reply dude, really appreciate it.

    here i can't hard code the ">=" as sometimes my boxWidth can be bigger than boxTargetWidth, therefore it will fire "delete box_mc.onEnterFrame" right away if i do that.

    my boxWidth is a variable that the number can be smaller or bigger than the boxTargetWidth. My goal here is I want to animate the box into different sizes when the respective buttons are clicked.

    cheers



    -------------------------------------
    if(boxWidth >= (boxTargetWidth-1)){
    box_mc._width=boxTargetWidth;
    delete box_mc.onEnterFrame;
    }
    -------------------------------------
    to me, design is a way of infusing life...

  8. #8
    Inspector General
    Join Date
    May 2001
    Posts
    493
    ah. i see. thanks for the explanation.
    have you used the moagrius approach?

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