
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
36
|
Chapter 3: Datatypes and Type Checking
Remember, these errors are your best friends. Don’t think of them as scolding you or
complaining about something that’s not your problem. You should thank the com-
piler for telling you when you’ve made a mistake, just as you’d thank your neighbor
for pointing out that you left your keys in your front door. Every time the compiler
generates a datatype-related error, think to yourself, “Wow, I just saved a few min-
utes or maybe a few hours tracking down that problem myself!”
In an object-oriented Flash application, be sure to provide a datatype for each prop-
erty, variable, method parameter, and method return value. If you omit the datatype
of an item, ActionScript 2.0 performs no type checking on it and cannot warn you
about datatype-related errors in your code.
In Chapter 4, we’ll study method definition again, in much greater detail.
Why Post-Colon Syntax?
As we’ve learned in this section, ActionScript 2.0 uses the following, slightly unusual
syntax for type declarations:
variableOrPropertyName:datatype = value;
By contrast, Java and C++ use:
datatype variableName = value;
In JavaScript 2.0: Evolving a Language for Evolving Systems, Waldemar Horwat (one
of the creators of the ECMAScript 4 specification) explains the reason for this differ-