For reference only:
Package {
Import flash. display. graphics;
Import flash. Geom. rectangle;
Public Function Drawdottedrect (graphics: graphics, rect: rectangle ){
VaR Sizeofdash: Number = 5 ; // Size of each Dash
Graphics. Clear ();
Graphics. linestyle ( 1 , Zero X 000000 , 100 );
VaR Iterations: Number = Math. Ceil (math. Abs (rect. Right - Rect. Left) / (Sizeofdash * 2 ));
For ( VaR I = 0 ; I < Iterations; I ++ ){ // Draw top
If (Rect. Right < Rect. Left ){
VaR Movedist: Number = - (Sizeofdash * 2 * I );
VaR DASH: Number = - (Sizeofdash );
} Else {
VaR Movedist: Number = Sizeofdash * 2 * I;
VaR DASH: Number = Sizeofdash;
}
Graphics. moveTo (rect. Left + Movedist, rect. Top );
If (I = Iterations - 1 ){
Graphics. lineto (rect. Right, rect. Top );
} Else {
Graphics. lineto (rect. Left + Movedist + Dash, rect. Top );
}
}
For ( VaR I = 0 ; I < Iterations; I ++ ){ // Draw bottom
If (Rect. Right < Rect. Left ){
VaR Movedist: Number = - (Sizeofdash * 2 * I );
VaR DASH: Number = - (Sizeofdash );
} Else {
VaR Movedist: Number = Sizeofdash * 2 * I;
VaR DASH: Number = Sizeofdash;
}
Graphics. moveTo (rect. Left + Movedist, rect. Bottom );
If (I = Iterations - 1 ){
Graphics. lineto (rect. Right, rect. Bottom );
} Else {
Graphics. lineto (rect. Left + Movedist + Dash, rect. Bottom );
}
}
VaR Iterations: Number = Math. Ceil (math. Abs (rect. Bottom - Rect. Top) / (Sizeofdash * 2 ));
For ( VaR I = 0 ; I < Iterations; I ++ ){ // Draw left
If (Rect. Top > Rect. Bottom ){
VaR Movedist: Number = - (Sizeofdash * 2 * I );
VaR DASH: Number = - (Sizeofdash );
} Else {
VaR Movedist: Number = Sizeofdash * 2 * I;
VaR DASH: Number = Sizeofdash;
}
Graphics. moveTo (rect. Left, rect. Top + Movedist );
If (I = Iterations - 1 ){
Graphics. lineto (rect. Left, rect. Bottom );
} Else {
Graphics. lineto (rect. Left, rect. Top + Movedist + Dash );
}
}
For ( VaR I = 0 ; I < Iterations; I ++ ){ // Draw right
If (Rect. Top > Rect. Bottom ){
VaR Movedist: Number = - (Sizeofdash * 2 * I );
VaR DASH: Number = - (Sizeofdash );
} Else {
VaR Movedist: Number = Sizeofdash * 2 * I;
VaR DASH: Number = Sizeofdash;
}
Graphics. moveTo (rect. Right, rect. Top + Movedist );
If (I = Iterations - 1 ){
Graphics. lineto (rect. Right, rect. Bottom );
} Else {
Graphics. lineto (rect. Right, rect. Top + Movedist + Dash );
}
}
}
}
Appendix:
Public Function drawdashedline (P: IPEN, XA: int, ya: int, XB: int, Yb: int, dashlength: INT): void
{
VaR U1: Number = XB-Xa;
VaR U2: Number = Yb-Ya;
VaR length: Number = math. SQRT (U1 * u1 + U2 * U2 );
VaR N: Int = math. Round (length/dashlength + 1)/2); // obtain the number of split Blocks
VaR V1: Number = u1/(2 * n-1); // get the X Increment
VaR V2: Number = u2/(2 * n-1); // obtain the incremental value in the Y direction.
For (var I: uint = 0; I <n; I ++)
{
VaR X1: Number = XA + 2 * I * V1;
VaR Y1: Number = ya + 2 * I * V2;
VaR X2: Number = X1 + V1;
VaR Y2: Number = Y1 + V2;
Drawline (p, math. Round (X1), math. Round (Y1), math. Round (X2), math. Round (Y2 ));
}
}