Article

Home » Design and Layout » Flash Tutorials » Flash Script - Ball and Line Effect

About the Author

SitePoint

View all articles by SitePoint...

Flash Script - Ball and Line Effect

By SitePoint

April 28th, 2003

Reader Rating: 8

Download the sample files here.

1. Create two circular objects, and make one larger than the other.

2. Convert both these objects into movieclips.

3. Give the larger circular object an instance name of "parent".

4. Give the smaller one the instance name "child1".

5. Create a diagonal line as shown below.

1081_tool1

6. Convert it to a movie clip and give it an instance name of "line".

7. Right click "child1", go to actions, and insert the action:

onClipEvent (load)  
{  
spring = false;  
startX = _x;  
startY = _y;  
spX = 0;  
spY = 0;  
_root.line._visible = 1;  
parentx = _root.parent._x;  
parenty = _root.parent._y;  
_root.line._x = parentx;  
_root.line._y = parenty;  
_root.line._xscale = _root.child1._x-parentx;  
_root.line._yscale = _root.child1._y-parenty;  
}  
onClipEvent (mouseDown)  
{  
startDrag ("", true);  
spring = true;  
}  
onClipEvent (mouseUp)  
{  
stopDrag ();  
spring = false;  
}  
onClipEvent (enterFrame)  
{  
parentx = _root.parent._x;  
parenty = _root.parent._y;  
_root.line._x = parentx;  
_root.line._y = parenty;  

//////  
_root.line._xscale = _root.child1._x-parentx;  
_root.line._yscale = _root.child1._y-parenty;  

//!spring = if false  
if (!spring)  
{  

//code to create the movements  
spX += (startX-_x);  
spY += (startY-_y);  
spX *= .09;  
spY *= .09;  
_x += spX;  
_y += spY;  
}  
}

8. That's it! Press ctrl+enter to test the movie.

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Sponsored Links

Rate This Article

  • 1
    Poor
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
    Great

Comment on This Article

Have something to say?

Post A Comment

You need to be a member of the SitePoint Forums to comment on this post. Sign Up

Already a member? Post using your SitePoint Forums account: