
Welcome Guest
|
#1
|
|||
|
|||
|
I have this red hanging lamp on my website and want it to swing either left or right depending on what side the mouse rolls over from so that it looks like the mouse gave it a small push. You can download the file I'm working on here: www.geocities.com/imagocreative/lamp.fla
I found a script for a pendulum that was posted a while back and tried to adapt it to my lamp but haven't been very successful yet. This is the script that I'm using: /* We need the function that will move our lamp. Basically, we have a parameter t that represents the time. We increment this on each frame to simulate time going forward. We put this value of time into our sine function, and then we mutliply by our scale factor a, whic represents the amplitude of the swing, and by another factor d, which will dampen the oscillation once we mouse off. */ function swinglamp(p:MovieClip) { //Apply our swing formula; var rot:Number = p.a * p.d * Math.sin(p.t); //Now set the rotation t this value; p._rotation = rot; //Increment the time; p.t += Math.PI / p.speed; } /* Now we need the onRollOver event; */ lamp.onRollOver = function() { //We need to give the lamp some inital parameters; //Amplitude (in degrees): this.a = 10; //The speed of oscillation (the bigger the number, the slower the oscillations); this.speed = 8; //Set the time; this.t = 0; //Set the damping (initally no damping, so set to 1); this.d = .5; //Set the onEnterFrame to our swinglamp function; this.onEnterFrame = function() { swinglamp(this); } } /* And then for the RollOut, all we do is slowly decrease the value of d. Once d falls below zero, we delete the onEnterFrame to save memory; */ lamp.onRollOut = function() { this.onEnterFrame = function() { swinglamp(this); //To make the lamp slow down more quickly, decrease this number (but not by a lot!) this.d *= 0.90; //Test to see if d < 0; if (this.d < 0) { this._rotation = 0; delete this.onEnterFrame; } } } Last edited by codeoverride : 10-10-2009 at 10:41 AM |
«
Previous Thread
|
Next Thread
»
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Movieclip to follow mouse | dalton | Newbies |
0 | 10-17-2008 02:42 PM |
| how to get somthing to follow the mouse at different speeds! | wildweelz | Flash MX 2004 |
1 | 09-21-2007 03:04 AM |
| mouse follow without easing | maverick_xj | Actionscript 2.0 |
4 | 09-13-2004 12:16 PM |
| how do i make a movie object follow the mouse? | a7ay | General Flash | 3 | 11-10-2003 11:45 PM |
| follow mouse direction | damn | Flash 5 Actionscript |
8 | 05-29-2001 10:07 PM |





