ActionScript: Filling a Shape with a Solid or Translucent Color

written by: Elis Frugalo; article published: year 2007, month 01;


In: Root » Computers and technology » Flash » ActionScript: Filling a Shape with a Solid or Translucent Color

Dutch French Spanish Portuguese Italian German Japanese Chinese Korean Russian Arabic Bookmark and Share this Article

Use the beginFill( ) and endFill( ) methods to initiate and close a shape drawn at runtime.

To draw a filled shape, call beginFill( ) prior to any other drawing methods, including the custom methods you have defined such as drawCircle( ) and drawPolygon( ). Invoke endFill( ) after calling other drawing methods to create the shape.

You cannot apply a fill to an existing shape drawn at authoring time or runtime. You must invoke beginFill( ) before drawing the shape to be filled.

This example creates a solid blue circle with a radius of 100 pixels:

_root.createEmptyMovieClip("shape_mc", 1);
// Tell ActionScript to begin a solid, blue fill.
   shape_mc.beginFill(0x0000FF, 100);
// Invoke a custom drawing method, such as drawCircle(  ), or invoke lineTo(  ) or
   // curveTo(  ) multiple times to create a closed shape.
   shape_mc.drawCircle(100);
// Call endFill(  ) to close the shape after other drawing methods have been called.
   shape_mc.endFill(  );

The beginFill( ) method requires two parameters:

fillColor
The RGB value to use for the fill

alpha
The value between 0 (transparent) and 100 (opaque) that controls the opacity

To create a translucent, filled shape, specify an alpha less than 100. If alpha is 0, the shape will appear unfilled. Don't forget to define a line style if you want the outline to be visible.

The endFill( ) method does not require any parameters. It simply ends the fill initiated with beginFill( ) or beginGradientFill( ). To avoid unexpected results, ensure that the pen returns to the starting point to complete the shape before invoking endFill( ).

Disclaimer

1) E-articles is not responsible for the information contained by this article as well for any and all copyright infringements by authors and writers. E-articles is a free information resource. If you suspect this article for any copyright infringement, please read the terms of service and contact us to investigate the problem.
2) E-articles is not responsible for inaccuracies, falsehoods, or any other types of misinformation this article may contain and will not be liable for any loss or damage suffered by a user through the user's reliance on the information gained here.

link to this article