A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: need help with easing. v v urgent :-(

  1. #1
    Senior Member
    Join Date
    Jan 2001
    Posts
    146
    hi,

    im making a menu system where i have two buttons, one left and one right arrow. below these arrows is one long mc which starts at 0,0 position and is four times the length of the stage.

    eg: the two arrows are on the left and right edge of the stage and the mc is below it. so when the movie starts, only the *** symbols can be seen

    < >
    *************++++++++++++++==============ooooooooo ooo

    when i click on the right arrow, the mc will move to the left and now only the +++ symbols can be seen. pressing the right arrow one more time will push it further to the left and now only the === symbols are seen and so on. pressing the left arrow will move the mc to the right.

    now im able to move it to the right place using actionscript, but i dont know how to show the movement. i want it to accelerate fast in the beginning and slow down as it reaches the desired position. i can do this using tweening but i would rather do it using script.

    can anyone help out with this. its really important because i havnt had much luck with other easing scripts and how to implement them.

    sid

  2. #2
    Senior Member
    Join Date
    Jul 2000
    Location
    Not on the dole any more
    Posts
    1,040
    What you need to do is calculate the distance between the current position and the 'target' position and divide this by a number greater than one. Then you add the result to the current position. Do this once per frame and the result looks like 'easing'. Here's some sample code:

    In your button
    Code:
    on (release) {
     _root.menuMovie.scroll = 1;
     _root.menuMovie.targetX += 100;
    }
    This of course assumes that your menu movie clip is called menuMovie and is in the main timeline -- you'll have to change this to whatever is appropriate in your movie. And of course, you'll need to change the value of 'targetX' to whatever you need it to be.

    Then in your menu movie clip:

    Code:
    onClipEvent (load) {
     speed = 3;
    }
    onClipEvent (enterFrame) {
     if (scroll) {
      diffx = targetX - _x;
      _x += diffx/speed;
      if (math.abs(diffx)  <=0.05) {
       scroll = 0;
      }
     }
    }
    Changing the value of speed will alter the speed with which the menu moves -- higher values will be slower (value must be greater than 1).

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