?
Solved

Springy Button Problem - Action Script 2.0

Posted on 2006-07-20
3
Medium Priority
?
377 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
1 Comment
 
LVL 3

Accepted Solution

by:
BishopNeo earned 2000 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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.

589 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