Limitations
Not all language features of ActionScript 3 have been implemented. The implemented features behave almost exactly as in ActionScript 3, but there are a few remaining limitations. It is planned to remove these limitations as far as possible in future releases.
- Each input file for the compiler must contain exactly one class in one package declaration. It is not permitted to define a class without a package (but you can use the top-level package). It is not permitted to put more than one class into an input file (even if only one is public).
- When a function overrides a function defined in the super class, the compiler does not check whether the override keyword is present. Vice versa, the override keyword may be present even when the function does not override. However, these checks are performed at runtime and result in a runtime Error. Moreover, IDEs do perform these checks during source code editing and issue a warning.
- The modifiers protected and internal are currently ignored (treated as public) although they are syntactically valid.
Binding Methods to "this"
In JavaScript, when writing b=o.m where m is a method defined in the class of o, the result is only the method m, not the method m bound to the object o. When you execute b(), the variable this will not be set to o as specified for ActionScript 3. The same holds true if b is a parameter assigned by a function call. A typical pattern where this occurs is handing in a callback function as a parameter.
Jangaroo provides two measures to support the ActionScript 3 semantics:
- If the compiler detects a usage of m that is not an invocation (not followed by parentheses) in the same source code file, you do not have to care about anything. The method is automatically declared as "bound", telling the runtime to bind it to the current object when that object is created.
- In all other cases, you have to use the helper function bind, which is defined by the Jangaroo runtime for all Functions, like so: o.m.bind(o). The outcome is a function that always invokes m with this bound to o. You can either create the bound method on the fly, or, if the code is executed multiple times, overwrite the method by the bound method once, like so: o.m = o.m.bind(o);
Type Casts
ActionScript features two different syntax constructs for type casts:
- type(expr) - the older syntax looks exactly like a function call.
- expr as type - the new syntax can easily be told apart from a function call.
Since the old type casts look like function calls, Jangaroo and Adobe strongly recommend using the new syntax.
The Jangaroo compiler simply generates a comment from the as-part or the old-style (just like for other type annotations). We currently do not insert code to verif a (down-)cast at runtime. Also, there are certain usages of type casts in ActionScript 3 which actually transform the value which i subject to the type cast. For example, a cast 42.4 as int perfoms a round operation in ActionScript 3, yielding the value 42. We are planning to implement these active type casts in a future Jangaroo release.