Solved

Springy Button Problem - Action Script 2.0

Posted on 2006-07-20
3
364 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
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.

920 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

16 Experts available now in Live!

Get 1:1 Help Now