Solved

Springy Button Problem - Action Script 2.0

Posted on 2006-07-20
3
368 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
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…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

734 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