O'Reilly logo

The ActionScript 3.0 Quick Reference Guide by Rich Shupe, Darren Richardson, David Stiller, Jen deHaan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 12. How Do I Draw with Code?

12.0 Introduction

In addition to importing assets, or creating them in the Flash authoring environment, you can include assets in your projects by drawing them dynamically with ActionScript at runtime. Much of the last half of this book will take advantage of this approach to minimize the number of custom assets required, and let you generate content exclusively with code. For that reason, this section starts off with a brief introduction to drawing with code.

A code-only approach doesn’t easily offer the artistic range afforded if you can use imported or hand-drawn assets, but significant tradeoffs include increased flexibility and reduced file size. Indeed, an entirely new creative horizon becomes available with code-generated art, and using ActionScript combined with previously created assets is, of course, the best of both worlds.

You have two primary methods of drawing with code: manipulating vectors with the Graphics class, and manipulating pixels with the BitmapData and/or related classes. This chapter will primarily focus on the former, but will also discuss a few simple pixel-based techniques, such as bitmap caching and basic filters.

Note

To effectively demonstrate some of the concepts in this chapter, you need to use a display object or two. Part I and Part II of this book covered the creation and use of display objects throughout, and you’ll look at some of those concepts again in Chapter 13. For clarity, however, the first recipe in this ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required