Flash as3 dotted line Reference

Source: Internet
Author: User

 

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 ));
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.