Skip to content

Language ~ Jangaroo for Native Speakers of ActionScript

Frank Wienberg edited this page Mar 14, 2014 · 3 revisions

Jangaroo for Native Speakers of ActionScript

Jangaroo is a subset of the ActionScript 3 language. It supports the following concepts of ActionScript that go beyond ordinary JavaScript:

  • classes including private and static members
  • packages
  • interfaces
  • imports
  • type annotations, including Vector.<type>
  • field initializers
  • default values for optional method parameters
  • include directives
  • same-file helper classes

The following concepts are not (yet) or only partially supported:

  • the with statement
  • package-scope functions
  • other member visibilities (internal, protected) and custom namespaces are syntactically accepted but ignored
  • XML initializers and query operators (E4X)
  • annotations (syntactically accepted but can only be accessed through proprietary API at runtime)
  • properties with getter and setter functions are supported in all modern browsers (Firefox, Safari, Chrome, Opera, IE9), but not in Internet Explorer before version 9

The definition of package-scoped functions is supported syntactically for the definition of ActionScript 3 APIs, but the compiler cannot generate runtime code for these yet. As a workaround (until we implement this feature), you may write your package-scoped functions in JavaScript and provide an ActionScript 3 API for it. We apply this appoarch in the Jangaroo runtime and libraries.

With-Statement

The missing with statement may come unexpected, because that is already available in JavaScript. However, the dynamic scoping provided by the with statement does not mix well with the statically scoped class-based approach of ActionScript 3. Maybe we will allow using with in a future release, but its use will always be discouraged.

Getter and Setter Functions

Jangaroo understands ActionScript getter and setter function syntax, which, for example, may look like this:

package {

public class Field {

  private var val : String;

  public function Field(value : String) {  
    val = value;  
  }

  public function get value() : String {  
    return val;  
  }

  public function set value(v : String) : void {  
    val = v;  
  }

}

At runtime, Jangaroo tries to define these methods using the predefined Object methods __defineGetter__ and __defineSetter__, or Object.defineProperty(). For a description of the feature (using the same example) and its current implementation state in browsers and Rhino, see John Reisig's excellent summary. To conclude, the feature is supported in all modern browsers (Firefox, Safari, Chrome, Opera, IE9) and Rhino, but not (yet) in Internet Explorer < 9. IE8 supports something similar, but only for DOM objects.

To keep your code browser-independent, we currently discourage using getter and setter functions, but use getValue() and setValue() methods instead. However, if you can require the clients to not use IE < 9 and/or you want to port existing AS3 code with as few changes as possible, using the feature is an option.

Another trick we use in the jangaroo-net library is to use getter and setter functions in an interface and implement them by functions declared as native. The Jangaroo compiler does not generate code for functions declared as native, so your IDE and ASDoc are satisfied, and everything works at runtime, because accessing the properties simply directly uses standard public properties. Of course, this method is only applicable for simple getters and setters, and not if you actually want to compute a value on get or trigger events on set. Still, it allows to define interfaces for simple getters and setters.

We are currently investigating ways to let the compiler generate special getter/setter emulation code for IE 7 and 8.

Further Limitations

Further notes on the current state of implementation can be found in the section on Jangaroo's limitations.

Clone this wiki locally