Flash Script – Spring Effect

By Georgina Laidlaw

Download the sample files here.

1. Create any object of your choice, and convert it to a movie clip.

2. Give it an instance name of "child1".

3. Right click the movie clip and insert these actions:

onClipEvent (load)  


spring = false;  

startX = _x;  

startY = _y;  

spX = 0;  

spY = 0;  


onClipEvent (mouseDown)  


startDrag ("", true);  

spring = true;  


onClipEvent (mouseUp)  


stopDrag ();  

spring = false;  


onClipEvent (enterFrame)  


//!spring = if false  

if (!spring)  


//code to create the movements  

spX += (startX-_x);  

spY += (startY-_y);  

spX *= .4;  

spY *= .4;  

_x += spX;  

_y += spY;  



5. The script is finished. Press ctrl+enter to test the movie.

Free Guide:

7 Habits of Successful CTOs

"What makes a great CTO?" Engineering skills? Business savvy? An innate tendency to channel a mythical creature (ahem, unicorn)? All of the above? Discover the top traits of the most successful CTOs in this free guide.

No Reader comments

Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in Front-end, once a week, for free.