This document applies to Flash 5 and assumes proficiency in
for Flash 4 version.
In Flash 5, as in Flash 4, there is still no Action to draw a straight line from one point
to another. This means that there's no "built-in" way
to write a script to draw a line from point A to point B.
However, it's possible to overcome this -at least partially- by scaling and positioning
a diagonal line so that the endpoints of the line are positioned on an
arbitrary two points. Please look at the picture below to see how
See sample application: Connect-the-dots.
For example, to draw a line from point (15,10) to point (50, 35), scale
a diagonal line so that the length of opposing side is
and the length of the adjacent side is (50-15)=35.
(If this is hard to conceptualize, just imagine scaling a square that
has a diagonal line connecting two endpoints.)
The technique is as follows:
Now, given 2 points P1(x1, y1) and P2(x2, y2), how do you draw a line from
P1 to P2? This is where scripting is required. The script
is actually pretty simple. It goes like this in pseudo code:
Note that the position of P1 and P2 doesn't really matter in the
calculation, as long as the P2 is the one being subtracted. (i.e.:
We don't need to worry whether P1 is on the right or below of P2.)
You might be wondering why use _xscale and _yscale
instead of _width and _height variables? The
reason is because Flash won't accept a negative value for _width and _height.