Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 25

Programming actionscript 3.0
Table of Contents

Advertisement

Many developers simplify the organization of their ActionScript code in the Flash authoring
tool by placing code only in the first frame of a timeline, or on a specific layer in the Flash
document. This makes it easier to locate and maintain the code in your Flash FLA files.
However, in order to use the same code in another Flash or Flex project, you must copy and
paste the code into the new file.
If you want to be able to use your ActionScript code in other Flash or Flex projects in the
future, you will want to store your code in external ActionScript files (text files with the .as
extension).
Embedding code in Flex MXML files
In a Flex development environment, you can include ActionScript code inside an
tag in a Flex MXML file. Inline ActionScript code like this has the same
<mx:Script>
drawback as code placed on a frame in Flash: you cannot reuse the code without cutting and
pasting it to a new source location.
You can specify a source parameter for an
ActionScript code as if it was typed directly within the
source file that you use cannot define its own class, which limits its reusability.
Storing code in ActionScript files
If your project involves significant ActionScript code, the best way to organize your code is in
separate ActionScript source files (text files with the .as extension). An ActionScript file can be
structured in one of two ways, depending on how you intend to use it in your application:
Unstructured ActionScript code: lines of ActionScript code, including statements or
function definitions, written as though they were entered directly in a timeline script,
MXML file, etc.
ActionScript written in this way can be accessed using the
ActionScript, or the
statement causes the contents of an external ActionScript file to be inserted at a specific
location and within a given scope in a script, as if it were entered there directly. In the Flex
MXML language, the
an external ActionScript file to be loaded at that point in the application. For example, the
following tag will load an external ActionScript file named Box.as:
<mx:Script source="Box.as" />
tag in Flex MXML. The ActionScript
<mx:Script>
tag lets you specify a source attribute that identifies
<mx:Script>
tag, which lets you insert
<mx:Script>
<mx:Script>
include
Options for organizing your code
tag. However, the
statement in
include
25

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents