Flex Tutorial: a dotted line painting example

Source: Internet
Author: User

 

This document uses two files: dashline. mxml and mydashline..

Dashline. mxml calls mydashline.

1. dashline. mxml

<? XML version = "1.0" encoding = "UTF-8"?>

<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "absolute" applicationcomplete = "myinit ();">

<Mx: SCRIPT>

<! [CDATA [

Private function myinit (): void {

VaR mydashline: mydashline = new mydashline ();

This. addchild (mydashline. myinit (2, 0xff0000, 0.9, 100,100,600,500, 5, 30, 25 ));

This. addchild (mydashline. myinit (2, 0xff00ff, 0.3, 100,500,600,100, 10, 30, 25 ));

}

]>

</MX: SCRIPT>

</MX: Application>

 

2. mydashline.

Package {

Import flash. display. graphics;

Import flash. display. Sprite;

Import flash. Geom. Point;

Import MX. Core. uicomponent;

Public class mydashline extends uicomponent {

Private var lines: SPRITE = new sprite ();

Private var component: uicomponent = new uicomponent ();

Public Function mydashline (){

Lines = new sprite ();

Component = new uicomponent ();

}

/* Myinit () function parameter annotation:

* 1. Number of shuliang dotted lines

* 2. linecolor dotted line color

* 3. Alpha value of linealpha dotted line

* 4. The value of the X axis at the starting point of the fromx dotted line

* 5. The value of the Y axis at the starting point of the fromy dotted line

* 6. The value of the X axis at the end of the tox dotted line

* 7. The value of the Y axis at the end of the toy dotted line

* 8. pointwidth thickness of a single vertex

* 9. The length of a pointlength point

* 10. interval between twopointdistance and twopointdistance

*

*/

Public Function myinit (shuliang: Number, linecolor: uint, linealpha: Number, fromx: Number, fromy: Number, TOX: Number, toy: Number, pointwidth: Number, pointlength: Number, twopointdistance: Number): uicomponent {

Drawdashed (lines. Graphics, linecolor, linealpha, new point (fromx, fromy), new point (Tox, toy), pointwidth, pointlength, twopointdistance );

Return component;

}

Private function drawDashed (graphics: Graphics, lineColor: uint, lineAlpha: Number, p1: Point, p2: Point, pointWidth: Number, pointLength: Number, twoPointDistance: Number): void {

Graphics. lineStyle (pointWidth, lineColor, lineAlpha );

Var max: Number = Point. distance (p1, p2 );

Var dis: Number = 0;

Var p3: Point;

Var p4: Point;

While (dis <max ){

P3 = point. interpolate (P2, P1, DIS/max );

DIS + = pointlength;

If (DIS> MAX ){

Dis = max;

}

P4 = point. interpolate (P2, P1, DIS/max );

Lines. Graphics. moveTo (p3.x, p3.y );

Lines. Graphics. lineto (p4.x, p4.y );

DIS + = twopointdistance;

}

Component. addchild (lines );

}

}

}

 

From: http://www.jinflex.com/index.php/archives/95

 

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.