Most JavaScript code is also syntactically valid ActionScript 3.0 code. However, there are some exceptions which leads me to my question:
Which constructs/features in JavaScript are syntactically invalid in ActionScript 3.0? Please provide concrete examples of JavaScript code (basic JavaScript code without DOM API usage) that is NOT valid ActionScript 3.0 code.
You can declare a variable in JS without using the var
statement. In ActionScript 3 the var
statement is always required.
The following is valid JS but will throw a compiler error in AS3:
var foo = 6;
bar = "bar";
You can also redeclare a variable in a single scope JS without an error:
var x = 5;
var x;
In AS3, you can only declare a variable once for each scope.
The obvious ones are ECMAScript 4 keywords that weren't future reserved words in ECMAScript 262 3rd Edition:
// oops!
var let = "Hello";
var yield = "World";
AS3 is a much stronger typed, and traditionally OO, language than javascript (and AS2), so all manipulation of prototypes is out. This is probably the biggest difference, IMO, since it means that something like jQuery can't really work in AS3.
As was pointed out, locals must be declared with var
. Also, untyped variables and redeclared variables generate compiler warnings.
You'll generally find that there's more examples of the other way around (AS3 code not being valid in javascript).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With