Chapter 8. Drawing with Vectors

IN THIS CHAPTER

The Graphics Class

The Geometry Package

9-Slice Scaling

Applied Examples

What’s Next?

Flash is well known for popularizing vector graphics on the Web. Put simply, vectors are composed of mathematically generated points, lines, curves, and shapes and are used to create artwork in computer software. Using vectors is optimal when you need to scale artwork because the vectors remain crisp and clean at any size. By contrast, bitmap graphics pixelate when scaled.

Drawing vectors graphics with code brings with it special benefits. Included among them is the freedom to create assets on the fly, rather than relying solely on art drawn or imported prior to publishing your file. Related to this is the additional bonus of reduced file size, because assets are created at runtime rather than occupying space in your SWF. Smaller files mean less time that your viewers spend waiting for your files to load.

In this chapter, we’ll focus on drawing vectors, the first of two ways to originate visual assets with code. Over the next several pages, we’ll cover:

  • The Graphics Class. This class, often referred to as part of the drawing API, contains methods for drawing vectors. You have control over stroke and fill attributes, and can move a virtual pen around the screen, choosing where to draw lines, curves, and shapes like circles and rectangles.

  • The Geometry Package. This utility package contains classes for creating points and rectangles, as well as transforming objects, ...

Get Learning ActionScript 3.0, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.