Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Valid JavaScript code that is NOT valid ActionScript 3.0 code?

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.

like image 390
knorv Avatar asked Mar 12 '10 00:03

knorv


3 Answers

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.

like image 144
Reuben Avatar answered Nov 18 '22 06:11

Reuben


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";
like image 44
Andy E Avatar answered Nov 18 '22 07:11

Andy E


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).

like image 4
Richard Szalay Avatar answered Nov 18 '22 06:11

Richard Szalay