Chapter 8. DRAWING WITH VECTORS

Drawing vectors with code brings with it special benefits. Included among them is the freedom to create assets on the fly, rather than be committed strictly to art drawn or imported at author-time. 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 your projects are delivered more quickly to the end user, and the experience is more enjoyable.

In this chapter, we’ll focus on the first of two ways to create visual assets with code—drawing vectors. The next chapter will focus on creating and compositing bitmaps.

  • The Graphics class. This class, casually referred to as the drawing API in its prior incarnation, contains methods for drawing vectors. You have control over stroke and fill attributes, and can move a virtual pen tool around 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 and their color, and creating matrices for complex simultaneous changes to rotation, scaling, and x and y translation. Using matrices, it’s possible to achieve affects for which no properties exist, including skew and shear.

  • 9-slice Scaling. Through the use of a dynamically assignable rectangle, you can employ 9-slice scaling to prevent the sides and corners of a sprite or movie clip from distorting when scaled.

  • Applied ...

Get Learning ActionScript 3.0 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.