Solved

Springy Button Problem - Action Script 2.0

Posted on 2006-07-20
3
362 Views
Last Modified: 2008-01-09
Hello Flash / ActionScript Gurus,

I am working on a project where I am using the attached buttons (download sample below). I am about 90% of the way home where I need to be, I just need to figure out one last problem. If you download and take a look at the sample (I am using Flash 8), you will see exactly what I am working with.

In the sample, the problem that I am trying to overcome is that I need the mouse NOT to stop the button movement until the buttons come completely to a rest (after they have completed their springy effect). I was thinking that I could accomplish this by disabling the mouse for a second or two, or even disable and re-enable the buttons (which are actually Movie Clips) for a short period of time (1 or 2 seconds), but I cannot figure out how to do this. Just click on the buttons and as you do so, move your mouse over the button that is coming back onto the screen and you should see it stop exactly where it is at, before it has returned to it's original point of origin.

Any help with this would be greatly appreciated! I have been banging my head against the wall on this for a few hours now, to no avail. There's also some pretty neat code in here for springy button movement that you could add to your own library in exchange for your help here, in case you don't already have it.

Thanks so much!

You can download the sample here:  http://www.veriatech.com/SpringyButtonSample.zip
0
Comment
Question by:dstjohnjr
3 Comments
 
LVL 3

Accepted Solution

by:
BishopNeo earned 500 total points
ID: 17155055
The solution is fairly simple, but it's one of those that don't immediately jump out at you.  The fix is to put what amounts to a semaphore variable in the tweening onEnterFunction and have the shiver function check for the variables state.  I redid both functions below, just paste them in place of your existing ones:

// springyXTween
      this.onEnterFrame = function()
  {
        this.__easing = true;
       // by storing the motion in the velocity variable, we retain inertia
       // and get the springy effect you want
            this.vx += (this.destX - this._x)*this.stiffK;
       // this line causes the motion to lose energy over time, otherwise we'd keep bouncing
            this.vx *= this.dampK;
            this._x += this.vx;
       // this checks to see if we're there yet, if so we stop calling this function
            if (Math.abs(this.vx) < .1 && Math.abs(this.destX - this._x) < .1)
            {
                  this._x = this.destX;
                    this.__easing = false;
                  delete this.onEnterFrame;
            }
      }

// shiver
      if(this.__easing){ return; }
      this.onEnterFrame = function ()
      {
            xScaleStep = (xScale - this._xscale) * strength + xScaleStep * weight;
            yScaleStep = (yScale - this._yscale) * strength + yScaleStep * weight;
            this._xscale += xScaleStep;
            this._yscale += yScaleStep;
      };


Again note, I only did the onEnterframe part since that's all you really need, with the exception of the shiver function where you need the single line *before* the onEnterFrame.

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now