Working with Movie Clips and Buttons > Using actions and methods to control movie clips > Drawing shapes with ActionScript |  |

Drawing shapes with ActionScript

You can use methods of the MovieClip object to draw lines and fills on the Stage as the movie plays. This allows you to create drawing tools for users and to draw shapes in the movie in response to events. The drawing methods are `beginFill`, `beginGradientFill`, `clear`, `curveTo`, `endFill`, `lineTo`, `lineStyle`, and `moveTo`.

You can use the drawing methods with any movie clip. However, if you use the drawing methods with a movie clip that was created in authoring mode, the drawing methods execute before the clip is drawn. In other words, content that is created in authoring mode is drawn on top of content drawn with the drawing methods.

You can use movie clips with drawing methods as masks; however, as with all movie clip masks, strokes are ignored.

To draw a shape:

1 | Use the `createEmptyMovieClip` method to create an empty movie clip on the Stage.
| The new movie clip is a child of an existing movie clip or of the main Timeline, as in the following example:
    _root.createEmptyMovieClip ("triangle", 1);
2 | Use the empty movie clip to call drawing methods.
| The following example draws a triangle with 5-point magenta lines and no fill:
    with (_root.triangle) {
    		lineStyle (5, 0xff00ff, 100);
    		moveTo (200, 200);
    		lineTo (300, 300);
    		lineTo (100, 300);
    		lineTo (200, 200);
    }

For detailed information on these methods, see their entries in the online ActionScript Dictionary in the Help menu.