最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

apache flex - Valid JavaScript code that is NOT valid ActionScript 3.0 code? - Stack Overflow

programmeradmin5浏览0评论

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.

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.

Share Improve this question edited Mar 23, 2010 at 14:00 knorv asked Mar 12, 2010 at 0:26 knorvknorv 50.1k77 gold badges220 silver badges296 bronze badges 4
  • javascript eval() function? – Buhake Sindi Commented Mar 12, 2010 at 0:34
  • 1 Not impossible to implement eval though. eval.hurlant.com/demo – spender Commented Mar 12, 2010 at 0:38
  • 1 someone downvoted everyone who answered this question too, all of us got a -1. +1 from me anyway, I think it's a perfectly good question to ask. – Andy E Commented Mar 21, 2010 at 19:25
  • 1 Not a bad question.. odd to give it bounty but to each his own. Not downvote worthy... – KP. Commented Mar 22, 2010 at 19:45
Add a comment  | 

6 Answers 6

Reset to default 8 +50

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

Actionscript 1 is much closer to Javascript. Actionscript 3 follows the now defunct ECMAScript 4 spec.

For one thing, the eval() method won't work.

Also, the RegExp() constructor doesn't appear to work, at least not with strings. In other words, you can't say:

var rex:RegExp = new RegExp("[a-zA-Z0-9]+","gim");

You have to write it like this:

var rex:RegExp = new RegExp(/[a-zA-Z0-9]+/gim);

In other words, you can't do variable substitution for parts of the string argument.

Well, you can't use alert (and some other JS global functions), onmouseover, onload, etc. (JS event handlers), anything that's form-related or browser-related (as you suggest). You can't copy and paste JS code in an AS3 class because AS3 is strongly typed and you can get compiler errors (moreover, in JS you have no classes at all).

发布评论

评论列表(0)

  1. 暂无评论