home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeActionScript: The Definitive GuideSearch this book

Appendix D. Differences from ECMA-262 and JavaScript

Naturally this book has focused on the intricacies of ActionScript, but if you own O'Reilly's excellent JavaScript: The Definitive Guide, you'll notice that the reference section of the two books share many similarities.

Although ActionScript, like JavaScript, is based on the ECMA-262 standard, certain differences were necessitated by the constraints of Player size and backward compatibility. If porting code from JavaScript, Jscript, or another ECMA-262-based language, you'll find Table D-1 valuable. It summarizes the intentional differences between ECMA-262, JavaScript, and Flash 5 ActionScript. Likewise, if porting ActionScript to another language, you'll be better able to avoid the pitfalls caused by ActionScript's deviation from the ECMA-262 standard.

Table D-1 reflects the intentional differences between Flash 5 ActionScript and the ECMA-262 standard. It does not reflect any bugs that may exist in its attempted implementation of the standard.

Table D-1. Differences Between ECMA-262, JavaScript, and ActionScript

Topic

Description

String-to-Boolean conversion

In ECMA-262, all nonempty strings convert to true. In Flash 5, only the strings that can be converted to a valid nonzero number convert to true.

Case sensitivity

The ECMA-262 specification demands complete case sensitivity. In ActionScript, keywords are case-sensitive but identifiers are not. See Chapter 14, "Lexical Structure", especially Table 14-1.

Function scope

When a function from one timeline is assigned to a variable in a different movie clip's timeline, the assigned function's scope chain changes to that variable's timeline. In ECMA-262, it's impossible to modify a function's scope chain through assignment; scope is determined permanently by the location of the function declaration statement.

Regular expressions

ActionScript does not support regular expressions.

Event handler names

Only object-based event handlers get their own named function in ActionScript (e.g., XML's onLoad( )). Movie clip event handlers are defined using onClipEvent (eventName), and button event handlers are defined using on (eventName). See "Event Handler Syntax" in Chapter 10, "Events and Event Handlers".

Global variables

ActionScript does not support true document-wide global variables. Global variables can be simulated by attaching properties to Object.prototype, as described under Section 12.5.4.4, "The end of the inheritance chain" in Chapter 12, "Objects and Classes".

The eval( ) function

ActionScript's eval( ) function supports a small subset of ECMA-262's intended functionality; it works only when its argument is an identifier and is used only to dynamically generate references to identifiers.

undefined datatype conversion

In ActionScript, the special undefined value converts to the empty string ("") when used in a string context and converts to the number when used in a numeric context. In ECMA-262, undefined converts to the string "undefined" in string contexts and to the numeric value NaN in numeric contexts.

The Function constructor

ActionScript does not support the Function constructor, which is used in JavaScript to create functions with the syntax new Function ( );.

Date object creation

ActionScript will not accept (i.e., will not parse) a human-readable date string such as "January 9, 2001" when creating a new Date object.

switch statement

ActionScript does not support the switch/case/default statements (used to phrase complex conditionals). See Section 7.4, "Simulating the switch Statement" in Chapter 7, "Conditionals".

Language support

ECMA-262 requires support of the Unicode character-encoding standard, which ActionScript does not support. ActionScript uses the Latin 1 and Shift-JIS character sets and implements a subset of Unicode-style functions and conventions (such as \u escape sequences).

Object model

Naturally, JavaScript includes built-in classes and objects that relate to web browsers, whereas Flash includes those that relate to Flash movies. For JavaScript programmers who are used to working with DHTML, it may be helpful to think of the main movie of a Flash document as being analogous to an HTML document object and movie clips as being analogous to layer objects.

Timed code execution

The setTimeout( ) and setInterval( ) methods of the JavaScript window object are not available in ActionScript but can be simulated with timeline and clip event loops as discussed in Chapter 8, "Loop Statements".

Object constructor

In Flash 5, the ActionScript constructor for the Object class does not accept any parameters. In ECMA-262, Object accepts a value parameter, which may be a Boolean, string, or number primitive.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.