Understanding ActionScript Syntax
Whether you’re writing ActionScript code inline, in an MXML script, or in a class, you’ll need to understand its basic syntax. The following sections look at the basic elements of ActionScript, such as class syntax, variables, statements, expressions, functions, and objects.
Understanding Packages
The majority of classes are organized into structures called packages. To understand most of ActionScript, you must understand what packages are and how you can work with them.
A package groups together classes so that you can ensure
uniqueness of scope. For example, you can have only one Button class within a scope. If you tried to
declare two Button classes in the
same scope, there would be a conflict; the compiler wouldn’t know which
one to use.
A package allows you to create several classes with the same name
by placing them in different scopes. For example, the Button class that’s part of the Flex framework
(i.e., the button UI component) exists within a package called mx.controls. When a class is placed within a
package, it has what’s called a fully qualified class
name. Therefore, the fully qualified class name for Button is mx.controls.Button. That ensures that if you
want to create another Button class
in a different package, you can do so without conflicting with mx.controls.Button. For example, mx.controls.Button and com.example.ui.Button (a
fictitious class) could exist within the same application without
causing a problem.
When classes are in packages, ...
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