Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Springy Button Problem - Action Script 2.0

Posted on 2006-07-20
3
Medium Priority
?
374 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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
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…
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 record live broadcast.
Suggested Courses
Course of the Month11 days, 21 hours left to enroll

916 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