Changes in Flash MX 2004
Flash MX 2004 is a major
upgrade for ActionScript users. Major additions include syntax and
structural changes that aid the building of large ActionScript
applications, greater support for text formatting, and greater
support for the control and running of media streams.
The Flash component framework has been upgraded to take advantage of
class-based optimizations and new features in ActionScript 2.0,
including strict datatyping.
Flash MX Professional 2004's new Slides and Forms
features (collectively called Screens) allow development using a
PowerPoint-like or Visual Basic-style authoring metaphor with a
minimum of scripting.
Even the Flash MX 2004 authoring tool's interface
can be customized using the Flash JavaScript API (JSAPI). See the
JSAPI Documentation section of the Flash MX 2004 Documentation page
(http://www.macromedia.com/support/documentation/en/flash)
for links to documents that explain how to create commands and tools
for use in the Flash authoring environment.
Furthermore, JSFL (Flash JavaScript), allows you to script authoring
operations. Complete coverage of JSFL is outside the scope of this
book, but here's a quick example of command-line
compilation for Windows. This JSFL script from Colin Moock tells
Flash to create the .swf file for each
.fla file in your project:
// Code in exportPetSupplies.jsfl:
// Open the .fla file.
var doc = fl.openDocument("file:///c|/data/projects/pet/petsupplies.fla");
// Export the .swf file.
doc.exportSWF("file:///c|/data/projects/pet/petsupplies.swf", true);
// Quit the Flash MX 2004 authoring tool (optional).
fl.quit(false);
// Command issued on command line from /pet/ directory:
"c:\program files\macromedia\flash mx 2004\flash.exe" exportPetSupplies.jsfl
For this command to work, Flash MX 2004 must not be running. After
the command is issued, the compiled
petsupplies.swf movie appears in the directory
c:\data\projects\pet.
Both Flash MX 2004 and Flash MX Professional 2004 support
ActionScript 2.0 but also still support ActionScript 1.0 syntax (you
can set which version of the ActionScript compiler to use under
File Publish Settings Flash ActionScript
Version). So developers can stick with ActionScript 1.0 or switch to
ActionScript 2.0, which is geared more toward object-oriented
development, at their own pace.
New ActionScript in Flash Player 7
Numerous additions to ActionScript in
Flash Player 7 are available whether you are using ActionScript 1.0
or ActionScript 2.0. Flash's online Help provides a
detailed list of the ActionScript changes (Help ActionScript
Reference Guide What's New in Flash MX 2004
ActionScript).
Here is a partial list of new features:
Real-time error message feedback via the Error
class, plus error handling via try/catch/finally
and throw. The ability to customize the Flash Player context menu via the
ContextMenu class and the new
menu property (for the
Button, MovieClip, and
TextField classes). Support for the Mouse.onMouseWheel event, which
detects changes in the mouse wheel position (Windows only) and an
undocumented way to detect mouse wheel clicks [Hack #62] . The MovieClipLoader class for creating
preloaders (i.e., for displaying load status while the SWF file
downloads). The TextField.StyleSheet class, which offers CSS
support. SOAP support, which allows Flash Player 7 to access SOAP-based web
services without requiring Flash Remoting to be installed on the
server. (Prebuilt remote data connectivity components that implement
SOAP communication are provided with Flash MX Professional 2004
only.) Some methods of the MovieClip class, most
notably getNextHighestDepth( ) and
getInstanceAtDepth( ) for depth management. The PrintJob class, which greatly simplifies
Flash printing and gives much more control over printed output than
the ActionScript 1.0 print functions.
Most Flash Player 6-format SWFs will play unmodified in Flash Player
7. However, Flash Player 7 also introduced a more stringent
interdomain security policy, as described in Chapter 12, which may break certain Flash Player 6
content when viewed in Flash Player 7. The
System.exactSettings property and the
System.allowInsecureDomain( ) method allow you
to change some of the domain security measures back to the less
stringent Flash 6 style, thus allowing more Flash Player 6-format
SWFs to run in Flash Player 7.
Although many of Flash Player 7's features are also
supported by Flash Player 6.0.65 (a.k.a. Flash Player 6r65), many
others are not. For maximum compatibility (until more end users
install Flash Player 7), you should export your Flash MX 2004 files
in Flash Player 6 format (choose File Publish
Settings Flash and select Flash Player 6 as the Version,
then check Optimize for Flash Player 6r65), unless you are using
Flash Player 7-specific features.
Case Sensitivity and Strict Typing
ActionScript 2.0 allows you to specify
the datatype for any property, variable, parameter, or function
return value. The datatype is used by the compiler to perform type
checking. That is, the compiler validates that only data of the
correct datatype is assigned to each item for which a datatype is
specified. ActionScript 2.0 is also case-sensitive (as discussed at
http://swfoo.com/archives/000034.html) to
bring it in conformance with the ECMA-262 Edition 4 (ECMA 4) proposed
standard as discussed in detail at http://livedocs.macromedia.com/flash/mx2004/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Flash_MX_2004_Documentation&file=01_what5.htm.
Although many nonprogrammers will see ActionScript
2.0's strict typing and case sensitivity as
something they can live without, it isn't hard to
use, and it can help you avoid errors. For example, in ActionScript
1.0, we could quite happily assign any data to a variable, like this:
answer = "Einstein";
However, further along in your timeline, you might mistakenly write
this:
answer = 6;
The preceding statement assigns a numeric value to what was supposed
to be a string variable, which is probably a mistake. ActionScript
1.0 could not detect such potential errors nor warn you about them.
However, using ActionScript 2.0's strict datatyping,
your code would become:
var answer:String = "Einstein";
Note the datatype, String, following the colon
(known as post-colon syntax). It specifies that
the answer variable should contain a string and
not a value belonging to another datatype. Whenever you define a
datatype for a variable, the variable must be preceded by the
var keyword.
Suppose that later in the timeline you use:
answer = 6;
When you try to compile the FLA, Flash warns you of the mistake by
displaying a type mismatch error in the Output panel. Using strict
typing thus tends to detect errors and help you create more robust
code.
ActionScript datatyping occurs at compile time in the authoring
environment only. ActionScript supports type checking only when you
choose ActionScript 2.0 as the ActionScript Version under
Flash Publish Settings Flash. Even when using the
ActionScript 2.0 compiler, Flash does not perform type checking on
any item for which you omit the post-colon datatype. This allows you
to update legacy ActionScript 1.0 to ActionScript 2.0, even if you
don't specify datatypes for every item.
LiveDocs
Keeping
up with all the features in Flash and ActionScript
isn't easy, especially since new bugs and updates
mean the in-product documentation is not necessarily current.
(Although if an Internet connection is available, Flash MX 2004 will
periodically ask you whether it should download updated
documentation.)
Although still in its early days,
LiveDocs for Flash
MX 2004 (http://livedocs.macromedia.com/flash/mx2004/index.html)
offers users online access to the full Flash documentation. LiveDocs
pages display other users' comments and include an
Add Comments button that allows you to comment on a
page's contents and usefulness.
Of particular interest is the online ActionScript
dictionary—just the place to go if you are having trouble with
getting a particular bit of code working and the in-product online
Help isn't sufficient to address your
question.
|