FlashMX Action draw method (medium)

Source: Internet
Author: User
Continued)
MovieClip. beginFill (rgb, alpha)
This command is used to set the fill color and opacity of the Closed Area drawn by the "virtual pen". The line is invisible if the rgb and alpha values of lineStyle are not specified.
RGB: It is used to set the fill color of the Closed Area. The setting method of lineStyle above is the same as that of hexadecimal code. If no color is specified, it is filled with black.
Alpha: It is of the same meaning as lineStyle and will not be described in detail.
Instance description:
Like lineStyle, you can use the default values of rgb and alpha by default. It needs to work with lineTo or curveTo (which will be preached later) to define the vertex positions of the Closed Area (that is, the intersection points of the lines in the Closed Area) to know the shape, size, and position of the closed area. Here is a simple example:

_ Root. beginFill (0x00FF00 );
_ Root. moveTo (100,100); // this is the origin
_ Root. lineTo (200,100 );
_ Root. lineTo (200,200 );
_ Root. lineTo (100,200 );

The as section will generate a green square, and the coordinates of the four vertices are:
(100,100); (200,100); (200,200); (100,200 ).
We can extend it by defining lineStyle:

On (release ){
_ Root. lineStyle (0x0000FF );
_ Root. beginFill (0x00FF00 );
_ Root. moveTo (100,100); // this is the origin
_ Root. lineTo (200,100 );
_ Root. lineTo (200,200 );
_ Root. lineTo (100,200 );
}

In this way, a blue transparent border with a border of 1 pixel can be obtained, and other parameters remain unchanged.
However, I strongly recommend that you close the filling image by bringing the last line back to the starting point of the image. Another problem with the code above is that the padding starts from the left, and the next lineto statement changes continuously. Another possible cause is that in the Code for sketching and filling, every time a moveto statement is added, the original filling is automatically closed and a new filling starts. Run the following code to see how it works (that is, if you do not close the drawn path in, the program automatically connects the first "point" and the last "point" to close the path to get a closed area .) See the following code:

_ Root. beginFill (0x00FF00 );
_ Root. moveTo (100,100); // This is the origin
_ Root. lineTo (200,100 );
_ Root. lineTo (200,200 );
_ Root. moveTo (100,200); // close the first filling area and start a new
_ Root. lineTo (200,300 );
_ Root. lineTo (100,300 );

In this way, we can get two equi-edge triangles.

MovieClip. endFill ()
This command does not include any parameters. It declares that it ends a beginFill command and clears the previous settings for the "pen". It cannot appear separately and can only appear in pairs with the beginFill command. Of course, you may not use it, just like the above as. We recommend that you develop a good habit of using endFill. The following as will draw a square:

_ Root. beginFill (0x00FF00 );
_ Root. moveTo (100,100); // defines the origin location
_ Root. lineTo (200,100 );
_ Root. lineTo (200,200 );
_ Root. lineTo (100,200 );
_ Root. lineTo (100,100); // closed path
_ Root. endFill (); // end Fill

This is a very neat as. In the following example, you can pull three handles to change the shape, position, and size of a triangle in real time.

Below is the core code:

// Place three handles on the stage to define the vertices of the triangle
_ Root. attachMovie ("squareHandle", "h1", 5 );
_ Root. attachMovie ("squareHandle", "h2", 6 );
_ Root. attachMovie ("squareHandle", "h3", 7 );
H1. _ x = 50;
H1. _ y = 150;
H2. _ x = 250;
H2. _ y = 150;
H3. _ x = 150;
H3. _ y = 50;
// Create an empty MC to place them
_ Root. createEmptyMovieClip ("mc", 1 );
// Define the draw Function
Function draw (){
// Clear previous filling settings
Mc. clear ();
// Set parameters for filling
Mc. beginFill (0x0000FF, 20 );
// Draw a triangle based on the three handles
Mc. moveTo (h1. _ x, h1. _ y );
Mc. lineTo (h2. _ x, h2. _ y );
Mc. lineTo (h3. _ x, h3. _ y );
Mc. lineTo (h1. _ x, h1. _ y );
// End Fill
Mc. endFill ();
}
// Refresh the function draw every 25 milliseconds.
SetInterval (draw, 25 );
// Complete the

MovieClip. clear ()
In the above as, we encountered this new command mc. clear (); its function is to clear mc. This includes setting of the mc itself and the objects contained in the mc, and restoring the parameters of the virtual pen to the default value.

Example:
At the beginning of this article, we have mentioned the necessity of clearing drawn, useless lines or shapes in a timely manner. Using clear can promptly release memory space without causing system crash. However, because it clears all objects, you have to "Draw" them again when you want to keep them.

The next section describes how to use as to draw an arc.

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.