Basic Structures
Now that you've had a crash course in display programming, you'll be happy to know that the basic structures in ActionScript 3.0 are very similar to earlier versions of ActionScript. Classes are handled differently, but if you're familiar with the way classes are used in ActionScript 2.0, you won't find too many differences. These structures are reviewed in this section along with a discussion of the different attributes associated with classes, variables and functions. Understanding these relationships is important for working successfully in object-oriented programming (OOP), the topic of the next section.
To get you started, we'll review data types and then classes and their attributes, along with how the different attributes work in different contexts. Let's start by reviewing data types.
Data Types
To successfully work with ActionScript 3.0, you need to use data types extensively and correctly. Data types are declared in ActionScript 3.0 by placing a colon before the data type and after the variable or constant name, as shown here:
var total:Number; const WARNING:String="Please enter your email address"; var strSize: uint = mystring.length;
With functions, the same rule applies except that the colon
follows the parenthesis after a function's name. The data type refers to
the return
type, if any return
statement is used. If no return
statement is used, the data type is
void
. The following illustrates how
to use data types with functions:
function getNumber() : Number ...
Get ActionScript 3.0 Programming: Overview, Getting Started, and Examples of New Concepts now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.