O'Reilly logo

ActionScript 3.0 Bible by Roger Braunstein

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 9. Vectors

FEATURED CLASSES

  • Vector

Vectors are a new addition to ActionScript 3.0 for Flash Player 10 and later. They can help you write fast, efficient, and concise code where you would otherwise use an array.

Vector Basics

A Vector is an optimized kind of Array that is made to store and retrieve instances of the same class. It behaves almost identically to an Array, but the key difference is that it stores only one type of object, as you can see in Figure 9-1.

In the original Array, you can store all kinds of objects together. In a Vector, you store only one kind. In the preceding example, the Vector only stores instances of Shoe. In this chapter, you'll see when and why this can be useful. I'll also cover the other minor differences between the two data types.

Note

FP10. Vector is available when compiling SWFs for Flash Player 10 and above.

Vectors are only available on Flash Player 10 and up. If you're reading this book sequentially, this is the first time you will have seen a whole class that is only available in certain versions of Flash Player.

An Array and a Vector compared

Figure 9.1. An Array and a Vector compared

Before I examine the when, why, and how of using Vectors, I'll take a moment to answer the next question:

Why Do We Need Another Datatype?

In many ways, ActionScript has been evolving backward, from a "modern" dynamically typed, high-level, object-oriented language toward a statically typed language ...

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