13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 12: Using the drawing API<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

Although imported images and artwork are important, the functionality known as the drawing API, which allows you<br />

to draw lines and shapes in ActionScript, gives you the freedom to start an application with the computer equival<strong>en</strong>t<br />

of a blank canvas, on which you can create whatever images you wish. The ability to create your own graphics op<strong>en</strong>s<br />

up broad possibilities for your applications. With the techniques covered here you can create a drawing program, make<br />

animated, interactive art, or programmatically create your own user interface elem<strong>en</strong>ts, among many possibilities.<br />

More Help topics<br />

flash.display.Graphics<br />

Basics of the drawing API<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

The drawing API is the name for the functionality built into ActionScript that allows you to create vector graphics—<br />

lines, curves, shapes, fills, and gradi<strong>en</strong>ts—and display them on the scre<strong>en</strong> using ActionScript. The<br />

flash.display.Graphics class provides this functionality. You can draw with ActionScript on any Shape, Sprite, or<br />

MovieClip instance, using the graphics property defined in each of those classes. (Each of those classes’ graphics<br />

property is in fact an instance of the Graphics class.)<br />

If you’re just getting started with drawing with code, the Graphics class includes several methods that make it easy to<br />

draw common shapes like circles, ellipses, rectangles, and rectangles with rounded corners. You can draw them as<br />

empty lines or filled shapes. Wh<strong>en</strong> you need more advanced functionality, the Graphics class also includes methods<br />

for drawing lines and quadratic Bézier curves, which you can use in conjunction with the trigonometry functions in<br />

the Math class to create any shape you need.<br />

Flash runtimes (such as Flash Player 10 and Adobe AIR 1.5 and later versions) add an additional API for drawing,<br />

which allow you to programmatically draw <strong>en</strong>tire shapes with a single command. Once you’re familiar with the<br />

Graphics class and tasks covered in “Basics of using the drawing API”, continue to “Advanced use of the drawing API”<br />

on page 234 to learn more about these drawing API features.<br />

Important concepts and terms<br />

The following refer<strong>en</strong>ce list contains important terms that you will <strong>en</strong>counter while using the drawing API:<br />

Anchor point One of the two <strong>en</strong>d points of a quadratic Bézier curve.<br />

Control point The point that defines the direction and amount of curve of a quadratic Bézier curve. The curved line<br />

never reaches the control point; however, the line curves as though being drawn toward the control point.<br />

Coordinate space The graph of coordinates contained in a display object, on which its child elem<strong>en</strong>ts are positioned.<br />

Fill The solid inner portion of a shape that has a line filled in with color, or all of a shape that has no outline.<br />

Gradi<strong>en</strong>t A color that consists of a gradual transition from one color to one or more other colors (as opposed to a solid<br />

color).<br />

Last updated 6/6/2012<br />

221

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!