The ActionScript 3.0 Quick Reference Guide
by Jen deHaan, David Stiller, Darren Richardson, Rich Shupe
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access