To draw with vectors, you must first reference the
graphics property of a display object. Then
you can access the methods and properties of the
Graphics class, which is responsible for
dynamic vector drawing. You can reduce code length and improve
performance by storing a reference to the property in a variable, and
using that variable thereafter where you would otherwise have referenced
the property directly.
If you want to draw into a display object, for example, such as
sp you created in the section called “12.1 Creating a Display Object Dynamically”, you can reference
graphics property like so:
var g:Graphics = sp.graphics;
Thereafter, you need only refer to
g when using a method or property of the
Graphics class. You can also
graphics property of
the main timeline with the following:
var g:Graphics = this.graphics;
This line of code assumes you are writing the script in the main
timeline, so the
this keyword refers
to the correct display object: the main timeline itself.
While it’s a matter of personal coding preference, drawing directly on the main timeline isn’t usually as useful as being able to contain your drawing in a display object you can manipulate later.