Basics of using the drawing API

Introduction to using the drawing API

The drawing API is the name for the functionality built into ActionScript that allows you to create vector graphics--lines, curves, shapes, fills, and gradients--and display them on the screen using ActionScript. The flash.display.Graphics class provides this functionality. You can draw with ActionScript on any Shape, Sprite, or MovieClip instance, using the graphics property defined in each of those classes. (Each of those classes' graphics property is in fact an instance of the Graphics class.)

If you're just getting started with drawing with code, the Graphics class includes several methods that make it easy to draw common shapes like circles, ellipses, rectangles, and rectangles with rounded corners. You can draw them as empty lines or filled shapes. When you need more advanced functionality, the Graphics class also includes methods for drawing lines and quadratic Bézier curves, which you can use in conjunction with the trigonometry functions in the Math class to create any shape you need.

Common drawing API tasks

The following tasks are things you'll likely want to accomplish using the drawing API in ActionScript, which are described in this chapter:

Important concepts and terms

The following reference list contains important terms that you will encounter in this chapter:

Working through in-chapter examples

While you're working through the chapter you may want to test some of the example code listings. Because this chapter deals with drawing visual content, testing the code listings involves running the code and viewing the results in the SWF that's created. To test the code listings:

  1. Create an empty Flash document.
  2. Select a keyframe in the Timeline.
  3. Open the Actions panel and copy the code listing into the Script pane.
  4. Run the program using Control > Test Movie.

    You will see the results of the code listing in the SWF file that's created.


Flash CS3

Take a survey


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00000176.html