Servicios Productos Telecargue Historia Contacto
 
Mi cuenta
 
Servicios
Servicios de consulta
Business Solutions
Calificaciones
Entrenamiento
Ayuda
 
Productos profesionales
molib™
the sandbox™
sswf™
odbcpp™
Trinity℠
¡Order Made!®
PHP eFax
PHP Pay Junction
Instant Cart™
DLF™
Documentos
 
Productos de consumo
Turn Watcher™
Telecargue nuestros productos
CafePress
Foros
 
Sobre nosotros
Historia
Noticias
Blogs
FAQ
Términos y condiciones
Privacidad
 
Contactar nosotros
Contacto
Carpeta de prensa
Trabajo
Solicitud de servicio
 
 
 
Idiomas disponible :  English   français 
 
ActionScript Language & Library


Check out our high quality products, exclusively for developers!


Alexis' ActionScript Compiler Reference
(started in September 2005)
SSWF V1.8.4

Summary

This document license

Language References

The SSWF Setup File

How do I use the Javascript compiler with SSWF?

Comments

Literals (numbers, strings, etc.) and Special Keywords

Reserved Keywords

Attributes

Expressions and Operators

Functions

Control Flow Statements

Classes, Interfaces and Enums

Packages

Pragmas

Namespaces

Compiler Internals, Known Bugs and Frequently Asked Questions

History of this reference





This document license

Copyright (c) 2005-2008 Made to Order Software Corp.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.






Language References

Thought the language for Flash is mainly devised by Macromedia, the actual reference is from Netscape. In version 7.x, the ActionScript compiler in Flash is actually a free version of the compiler from Netscape most certainly based on ECMAScript version 3 and tweaked by Macromedia to support some of the features of the following version. The current version (at time of writing) is based on a proposal by Netscape to the ECMAScript people. This is version 4 which isn't official yet (we're in 2005 and the proposal was written in 1999.)

You can find the ECMAScript 4 Netscape Proposal on the Mozilla website at this time. (Search for "ECMAScript 4 Netscape Proposal" in some search engine if the link below does not work anymore at the time you click on it...)

On that page, you have a access to a PDF which describes ECMAScript 4 as (supposedly) currently in the work by the ECMA people.

Another reference is of course the complete reference from Macromedia. You can find ActionScript v8.0 fully described. Note that includes many objects implemented by Flash developers and not actually implemented in the Flash Player. These objects are part of the mx package. Everything else should be available in the player (Sorry! I won't take the time to test that for you to make sure... we'll have to go and find problems as they arise.)

There are other sources for JavaScript, but only the Netscape Proposal is sensical in being used to write a compiler which is what I've done.





The SSWF Setup File

In order to accomodate the ActionScript support, SSWF now reads a setup file which includes some information about where to find the default packages and where to save the package database. It also includes a version, so we can make sure that we are reading the proper information.

The setup file is named sswf.rc and it is searched in order in this list of directories:

  • Current directory ("."),
  • Include directory under the current directory ("include/sswf/scripts"),
  • The hidden SSWF directory in your current directory (".sswf"),
  • The hidden SSWF directory in your home directory ("~/.sswf"),
  • The visible SSWF directory in your home directory ("~/sswf"),
  • The normal Unix setup directory ("/etc"),
  • The SSWF directory within the Unix setup directory ("/etc/sswf") — note that this is the default installation directory for the SSWF setup file,
  • The SSWF scripts include directory ("/usr/include/sswf/scripts"),
  • The SSWF scripts directory ("/usr/share/sswf/scripts"),

The file is composed of shell like variables (<name>=<value>). The table below lists the values currently understood by SSWF. The file can also include empty lines and lines commented out. Comments are like in a shell script, they start with a hash (#) and end with the end of the line.

Literal
Name
Comments Default SSWF
Availability
version Specify the SSWF version when this file was installed. You may need to bump this version up and change some other variables to use newer versions of the file.

Example:
	version=1.7.3
required 1.7.3
asc_path Defines the path where the SSWF compiler will find the system packages. In that directory, the compiler expects to find three or four sub-directories: global, system, native and the optional extensions directory. In order to initialize the packages automatically, these directories are expected to include a file named as_init.asc. This file is automatically loaded and compiled. It usually includes an import statement used to automatically make the Global, System and Native packages visible. This way, the end users do not have to specify any import for the system to work.

Example:
	asc_path=/usr/share/sswf/scripts
required 1.7.3
asc_db Specify a fullpath to the package database file. It needs to be somewhere you can read and write a file. If you are creating a system for multiple users, then make sure you use a sub-directory in the users home directory. This is important since each user may have different packages and these may not be available to all the other users. Also, all users need to have write access to the package database file.

You can specify a path which is not a fullpath. For instance, you can use asc_db=sswf/asc_database.db. This is fine, but anywhere you use SSWF, you will need to have a sub-directory named sswf.

A better way, is usually to ask the users to create a sub-directory named sswf (or .sswf) in their home directory (i.e. mkdir ~/.sswf) and then to setup this file to make use of that directory: asc_db=~/.sswf/asc_database.db. The ~ will automatically be replaced with the user's home directory.

The name of the database file can be anything. It is suggested that you use asc_database.db though (the default).

Example:
	asc_db=tmp/sswf-db.txt
~/.sswf/asc_database.db 1.7.3




How do I use the Javascript compiler with SSWF?

The actionscript compiler is actually in a library. The SSWF compiler links against that library and thus includes the functionality directly inside its language. Whenever you need to write an actionscript in an SSWF file, you now can use the actionscript object.

	do action {
		actionscript test {
			// do something useless
			var b: Integer, c: Integer, d: Integer, e: Integer;
			var a: Integer = (b + c * d) ** e;
		};
	};

The scripts themselves are mostly Javascript compliant. Some features are either not yet implemented or may work in a slightly different way than expected, but in general, it will work the same. (Most of you will be just fine. As long as you do not try all the most advance features of the language... you know!)

So, in order to learn the basics, I suggest that you read Javascript manuals. That will give you most of what you need to understand the basic flow control statements, expressions, the exception hanlding and the global classes: arrays, strings, numbers, dates, functions, math, boolean and errors. All of this is described in this documentation but only briefly. This documentation isn't a tutorial.

On the other hand, in this documentation you will find what is and what is not working in this implementation. Also, there are extensions available in the SSWF version which you may want to use in your scripts. For instance, you can use the ?< and ?> operators to retrieve the maximum or minimum of two or more expressions. Similarly, the SSWF version supports overloading of operators. Here too, we went beyond the specification and we authorize nearly all the operators to be overloaded.

Finally, this documentation describes all the objects available in the SSWF implementation: the Global objects (such as Integer and String), the System object specific to Flash and the Native objects which are used to manipulate all the objects available in Flash such as sprites (called movie clip?!), buttons, cameras, colors, etc. That you can also find on the Macromedia website.

Please, refer to the actionscript object in the Reference to the Scripting language for SWF for more information on how to include an actionscript in your SSWF scripts.

ActionScripts which include class or interface definitions can't be defined within a sprite. This is because a sprite can't be defined as a child of another sprite (it can only be referenced and viewed as a child, not defined). And internally, classes and interfaces are sprites. However, SSWF takes care of extracting these classes accordingly and thus as an end user you can declare anything anywhere it is legal in Javascript.





Comments

This implementation of ActionScript supports two types of comments.

The regular multiline C comment introduced by /* and ending with */. Note that you cannot include a comment in another comment (as per the ECMAScript documentation.) Thus, the first */ found closes a comment.

	/* my comment
	   can span
		 on multiple
		 lines */

The regular one line C++ comment introduced by // and ending with the end of the current line. Note that all the characters are ignored in that comment and thus another comment introducer (// or /*) will be ignored.

	// a one line comment

If you need to comment out a block of instructions between { and } then you can simply mark them false. This is the best way to comment out a whole block whether it includes C comments or not.

	false {
		if(quit) {
			exit();
		}
	}




Literals

This implementation of ActionScript supports the literals as described in the table below.

Literal
Name
Comments SSWF
Availability
__CLASS__
String
The special identifier __CLASS__ is automatically transformed by the compiler into the name of the class in which it is found. It is an error to use it outside a class. It works when used in a sub-interface of a class. 1.7.4
__DATE__
String
The special identifier __DATE__ is automatically transformed by the compiler into a string representing the date at which the code is being compiled. This can be used later as a time stamp. Note that if you use dynamic compiling, it may not be very useful. For Flash, it will give you an indication of when it was compiled. 1.7.4
__DATE822__
String
The special identifier __DATE822__ is automatically transformed by the compiler into a string representing the date according to RFC-822 at which the code is being compiled. This can be used later as a time stamp. Note that if you use dynamic compiling, it may not be very useful. For Flash, it will give you an indication of when it was compiled. 1.7.4
false
Boolean
The boolean value false. It is also often represented by the number 0. See the value true for more information. 1.7.3
__FILE__
String
The special identifier __FILE__ is automatically transformed by the lexer into the name of the file currently being parsed. This is the same as __FILE__ in the C/C++ preprocessor. 1.7.4
__FUNCTION__
String
The special identifier __FUNCTION__ is automatically transformed by the compiler into the name of the function in which it is used. It is an error to use it outside a function. Only the inner most function name is returned. 1.7.4
__INTERFACE__
String
The special identifier __INTERFACE__ is automatically transformed by the compiler into the name of the interface in which it is found. It is an error to use it outside an interface. It works when used in a sub-class of an interface. 1.7.4
__LINE__
Integer
The special identifier __LINE__ is automatically transformed by the lexer into the name of the file currently being parsed. This is the same as __LINE__ in the C/C++ preprocessor. 1.7.4
__NAME__
String
The special identifier __NAME__ is automatically transformed by the compiler into the fully qualified name of the function, class, interface and package in which it is used. When used outside all of these, then it returns an empty string. Only the inner most package name is returned. This is used with the trace() special command. 1.7.4
null
Object
The null value is used for variables which are used as references to objects. This marks the references as not used. If you set a variable to null and that was the last variable referencing an object, it will automatically delete that object (I think... TBP -> to be proven!). 1.7.3
__PACKAGE__
String
The special identifier __PACKAGE__ is automatically transformed by the compiler into the name of the package in which it is used. It is an error to use it outside a package. Only the inner most package name is returned. 1.7.4
super
Object
The special identifier super is a reference to the super class instance. That's the class we are derived from. For instance, in the following, super references to class A:
	class A { function test() {} }
	class B extends A { function test() { super.test(); } }

Note: if you are interested to know, this is the reason why you cannot have more than one extends on a class. There are several ways to fix this problem, but since Macromedia Flash does not support more than one extends (and the ECMAScript reference also mentions just one,) we will stick with it the way it is.
1.7.3
this
Object
The special identifier this is a reference to an object. It is available in functions which are dynamically declared as members of an object or defined in a class.

Note: in Flash, this is always defined because wherever you run a script you will always be in some object. The primary environment is the _root which is a MovieClip object (a sprite.)
1.7.3
__TIME__
String
The special identifier __TIME__ is automatically transformed by the compiler into a string representing the time at which the code is being compiled. This can be used later as a time stamp. Note that if you use dynamic compiling, it may not be very useful. For Flash, it will give you an indication of whem it was compiled. 1.7.4
true
Boolean
The boolean value true. It is also often represented by the number 1. However, if you try to call a function with a pre-defined prototype, you will need to use the correct type and thus a boolean value if need be. 1.7.3
undefined
undefined
The undefined value is used anywhere a reference is left undefined. For instance, if you mark a function with some parameters which do not need to be passed by the caller, these parameters will be set to undefined unless the caller defines them. 1.7.3
__UNIXTIME__
Integer
The special identifier __UNIXTIME__ is automatically transformed by the compiler into an integer representing the time at which the code is being compiled. This can be used later as a time stamp. Note that if you use dynamic compiling, it may not be very useful. For Flash, it will give you an indication of whem it was compiled. 1.7.4
__UTCDATE__
String
The special identifier __UTCDATE__ is similar to __DATE__ using Universal Time Coordinate. 1.7.4
__UTCTIME__
String
The special identifier __UTCTIME__ is similar to __TIME__ using Universal Time Coordinate. 1.7.4
.+
identifier
An identifier is defined as all the non-punctuation characters and thus it is a pretty large set. The usual identifiers are defined as letters, digits and underscores. It cannot start with a digit. 1.7.3
[0-9]+\.[0-9]+[eE][+-][0-9]+
numbers
The syntax for numbers is a string of digits with an optional decimal point and exponent. The use of the decimal point transforms the number in a floating point. Note that you do not need any digits before the decimal point in which case it is considered as being zero (.9 and 0.9 are considered the same.) A floating point number can optionally end with an exponent (at this time, you cannot use the exponent syntax for integers). Integers can be specified in decimal (the default) or hexadecimal when they start with 0x or 0X in which case digits and letters from A to F can be used. When the octal pragma option is turned on (by default it is off as per the specification), you can start a number with a zero and continue with digits 0 to 7 to form an integer in base 8.

Note 1: this syntax does not allow for a number to be followed by a member operator; we may fix that at a later date, though you can still put the number between parenthesis: (5).ToString() will work.

Note 2: this syntax also does not allow for the compiler to understand something like this: 5.....2, without a bit of luck. In this case it works. It finds the floating point number 5., then the rest operator (...) and finally the decimal number 0.2. Still, you should use spaces to separate floating point numbers and the rest or range operators. In this case: 5..2, the compiler cannot see 5 .. 2 as one would eventually expect.
1.7.3
"..." or '...'
String
Define a literal string between a set of single or double quotes. Inside the quotes you can use a backslash to escape a quote character, a blackslash or insert a control character using either a letter or a value.

Characters Comments
\xhh or \Xhh Read one or two hexadecimal digits and convert them in a Unicode character
\uhhhh Read up to 4 hexadecimal digits and convert them in a Unicode character
\Uhhhhhhhh Read up to 8 hexadecimal digits and convert them in a Unicode character
\ooo Read up to 3 otal digits and convert them in a Unicode character
\' \" \\ Keep the character as is (', " or \)
\b Insert the backspace control character
\e Insert the escape control character; this is an SSWF extension and it can be turned off with a pragma
\f Insert the form feed control character
\n Insert the new-line control character
\r Insert the carriage return control character
\t Insert the horizontal tabulation control character
\v Insert the vertical tabulation control character
anything else In all other cases we get a question mark which represents an erroneous escape sequence; as an extension, I may later add an option so any character is accepted and simply not converted however this isn't in the reference
1.7.3
`...`
regular expression
The default ECMAScript definition declares regular expressions between / and /. There are several problems linked with that syntax, the most obvious is the divide sign which looks very much alike. The solution is to see any / as a divide sign if possible. This is complicated to say the least. The other problem is that a mistake can change the start of the sequence in a comment introducer /* ... and that too can be really hard to detect. It is an invalid regular expression, but it could happen. My solution is to use backward quotes for regular expressions. This simple trick resolves all of these problems. At this time, SSWF does not really do anything with regular expressions, but the literal is already supported for future compatibility. See the match operator for one usage example. The content of a regular expression is exactly the same as the content of a string. You can use the same escape sequences. 1.7.3
[ <expr>, ... ]
array declaration
Declares an array inline. This syntax allows you to define an array with the values as defined by the list of expressions defined between the [ and ]. It is valid to declare an empty array ([]). The result of this expression is a reference to the newly created array. You can save arrays in variables or use them as function parameters. 1.7.3
{ <label> : <expr> , ... }
object declaration
Declares an object inline. This syntax allows you to define an oject with properties and their values as defined by the list of labelled expressions defined between the { and }. The result of this expression is a reference to the newly created object. You can save inline objects in variables or use them as function parameters. 1.7.3




Reserved Keywords

The language has a set of reserved and special meaning keywords. Reserved keywords are recognized by the low level lexer and they cannot be used as identifiers anywhere. The special meaning keywords can however be used as regular identifiers in places other than where they have that special meaning.

The ECMAScript language reference says that an identifier with an escape sequence cannot be a keyword. I do not see the point. Escape sequences are being parsed at the time the text is read and if the resulting identifier is a reserved keyword, it is reserved in SSWF. (Also, what is the point of having escape sequences in identifiers? I would think that you can use UTF-8 or Unicode if you want to write identifiers in your own language and not have to use escape sequences anywhere. A variable name such as: être will never be a keyword.)

Keyword Comment SSWF Availability
abstract (*) This is just noise. It is an attribute to a function to make sure you know that it is on purpose that no body was defined. This is not a keyword in SSWF, just a function attribute. You cannot use this attribute and declare a function body or you get an error. 1.7.3
as The 'as' operator. 1.7.3
break Break a for, while or do loop. Break a switch statement. Note that you can use the autobreak attribute on switch statements so it automatically breaks between cases (except empty ones, as in: cases not followed by any statements but immediately with another case.) With a label you can directly break to the end of the named loop or switch. 1.7.3
case Defines one case in a switch statement. Note that multiple cases one after another can be used to enter the same list of statements. In this special case, even the autobreak switch attribute has no effect. 1.7.3
catch Catch exceptions. 1.7.3
class Defines a new class (also called type). 1.7.3
const Defines a constant variable. SSWF accepts 'var' right after 'const'. This is not in the ECMAScript specification. But it doesn't break anything. 1.7.3
continue Repeats a for, while or do loop. With a label, you can also repeat a named loop (it will break all the inner loops and then repeat the named loop).

SSWF enables you to continue a switch statement. For a switch statement, the continue statement must use a label. It will continue testing the switch cases. If no other case statement matches, then the continue acts like the break statement. Without a label, the continue acts as expected in ECMAScript: it continues the loop it is defined in.
1.7.3
debugger (*) Send some information/commands to a debugger. n.a.
default The default statements to execute in a switch statement when none of the case statements matched. Also the label of a break or continue statement in order to reference the current loop (it is not required). 1.7.3
delete Delete an object. 1.7.3
do Defines a do ... while() loop. 1.7.3
else Defines the statement to execute when an if() expression is false. 1.7.3
enum SSWF supports this extension which defines an enumeration type. Each entry represents a value which is automatically incremented if not assigned. Also, the assigned value can be dynamic! (Defined as a non-constant expression only known at runtime.) 1.7.3
export (*) SSWF does not define this keyword yet. I'm not too sure what it could be for. In Javascript you do not export, you just define packages. n.a.
extends (*) A class can extend another using this keyword. 1.7.3
false The literal value false. 1.7.3
finally The part to execute before exiting a try block whether an exception was received or not. 1.7.3
for Defines a for and for each loop. 1.7.3
function Declares a function. 1.7.3
get (*) This identifier has the special meaning of creating a getter function when used within a function name declaration. It needs to be followed by another identifier which represents the actual name of the getter. n.a.
goto Go to a user defined label. Note that this is an SSWF extension. 1.7.3
if Starts an if/then[/else] statement. 1.7.3
implements List interfaces implemented by this class. 1.7.3
import Specify system and user extension modules to import. 1.7.3
in The 'in' operator in expressions and for loops. 1.7.3
instanceof The 'instanceof' operator in expressions. 1.7.3
interface Defines a class which is not derived from Object. We can call this a standalone class, however you cannot create an object from just an interface definition. 1.7.3
is The 'is' operator in expressions. 1.7.3
namespace Defines a new namespace. Makes a namespace visible. n.a.
native (*) This is marked as a possible extension keyword. To me it looks like an attribute and it does not need to be a keyword in SSWF. n.a.
new Create a new object. 1.7.3
null The 'null' literal. 1.7.3
package Starts the declaration of a package. 1.7.3
private Marks the following declaration as private to this class. This is an attribute, however it is viewed as a keyword so it cannot be used as a variable or a function name. 1.7.3
protected (*) Marks the following declaration as protected to this class. This is not a keyword in SSWF. It can be used as an attribute and will mark variables and functions as only accessible from this class and extensions of this class. 1.7.3
public Marks the following declaration as public to this class. This is an attribute, however it is viewed as a keyword so it cannot be used as a variable or a function name. 1.7.3
return Returns a value from a function. 1.7.3
set (*) This identifier has the special meaning of creating a setter function when used within a function name declaration. It needs to be followed by another identifier which represents the actual name of the setter. n.a.
super Reference to the super object of this object. 1.7.3
switch Starts a switch statement. 1.7.3
synchronized (*) Defines a variable or function which can be accessed only by one thread at a time (this is really just a guess, I have no idea what this is for). At this time SSWF does not recognize this statement since it could most certainly be an attribute and thus does not need to be a reserved keyword. As far as I know, "threads" under Flash are run serially anyway. A sprite is considered to be a thread. n.a.
this Reference to the object of which a function member is being executed. 1.7.3
throw Throws an exception. 1.7.3
throws (*) This is a keyword reserved for future use in ECMAScript. It looks to me that could very well be an attribute to a function to indicate that it may throw an exception so SSWF does not define this as a keyword. n.a.
transient (*) The transient attribute will only be an attribute and thus not a keyword in SSWF. n.a.
true The literal value true. 1.7.3
try Runs a set of statements safely (with guards). In case an exception occurs one of the following catches will be executed. To clean up, the finally statements are executed whether an exception occured or not. 1.7.3
typeof This statement returns the name (as a string) of the type of some arbitrary object. 1.7.3
undefined ECMAScript version 4 does not define this identifier as a keyword. It is a keyword in SSWF. 1.7.3
use Defines a pragma or starts using a given namespace. Some pragmas are available in version 1.7.3. Namespace are not yet supported by the compiler (the parser accepts them though.) 1.7.3
var Starts the definition of a variable. 1.7.3
void Marks an expression as void. [not too sure why we need void and Void; SSWF sees both as the same type] 1.7.3
volatile (*) The volatile attribute will only be an attribute and thus not a keyword in SSWF. n.a.
while Creates a while loop. 1.7.3
with Creates a block of statements which can access the given object members without using its reference each time. 1.7.3
(*) keywords marked with an asterisk are not reserved meaning that when used in a context other than the one intended for that keyword, it is viewed as an identifier.



Attributes

Definitions in your code can receive a list of attributes. Definitions are functions, blocks of declarations1, packages, classes, variables, etc.

1a declaration is a definition or a statement.

All the definitions will always accept true and false. A definition marked true (the default when not marked either true or false,) means that the definition is to be used. A definition marked false, is a definition which needs to be ignored. This allows for dynamic compiling similar to a pre-processor. Whenever you include a package, using the true and false attributes, you can turn on and off different features. For instance, you can have a debug and a release version of some code. In the example below, the do_something() function writes some extraneous messages in a console when attr_debug is set to true.

	// NOTE: this example is not yet functional (as of v1.7.3)
	// in some package
	package that_package {
		function do_something(a, b, c)
		{
			...
			attr_debug {
				echo("We came through here");
			}
			...
		}
	}
	// in some program file
	const var attr_debug := true;
	const var attr_release := !attr_debug;
	...
	import that_package;
	...

In this example, we define the value for attr_debug to true. Then the echo() function is compiled. [Note: an external package will not look outside itself for variables; that's a problem for this pre-processor! I will look into a fix in a later version of SSWF to support this mechanism.]

The attributes, by definition, are a list of names put in front of a definition and understood by the system. They can be used directly or put in a constant variable. When defined in a variable name, that name can be used instead of the attribute. In effect, it makes it a dynamic attribute. Note that a variable can reference another variable. All the variables need to be constants. The name of the variables cannot be the name of any of the currently supported attributes. The special true and false attributes can be negated with the logical not operator.

The attributes understood by such and such definition are listed along that definition documentation. The following is just a list of all the attributes currently understood and which definitions understand it. The ones underlined are also reserved keywords.

Attribute Definitions SSWF
Availability
abstract member functions n.a.
array all functions 1.7.3
autobreak 1 switch statements; forces a break between each case (except empty ones, as in: cases without statements) 1.7.3
constructor member functions 1.7.3
dynamic classes, variables and functions 1.7.3
enumerable class members (variables and functions) visibility; see for (enumeration) 1.7.3
false all definitions 1.7.3
final classes, member functions and variables 1.7.3
foreach 1 switch statements; assumes a continue on each case 1.7.3
internal functions, classes, interfaces and variables inside a package 1.7.3
intrinsic packages, classes, interfaces, functions, variables 1.7.3
nobreak 1 switch statements; this is the default which is to not automatically break between cases (fallthrough) 1.7.3
private member functions and variables of packages and classes 1.7.3
protected member functions and variables of classes 1.7.3
public member functions and variables of packages and classes 1.7.3
static member functions and variables of classes 1.7.3
true all definitions 1.7.3
unused all functions 1.7.3
virtual member functions of classes 1.7.3

1 switch statements get their attributes defined right before their block of statements; for instance one can write the following:

	switch(expr) with(<) foreach {
	case 0:
		// executed when 'expr < 0' is true
		...
	case 1:
		// executed when 'expr < 1' is true
		...
	case 2:
		// executed when 'expr < 2' is true
		...
	default:
		// always executed
		...
	}

In this example, if expr is 1, then the statements of case 1, case 2 and default are all executed. To avoid executing default after case 2, use a break statement. (similarly, you can break any one case to avoid the foreach effect.)





Expressions and Operators

This implementation of ActionScript supports the operators as descibed in the table below. Note that some of these operators are extensions to the standard. You can make sure not to use them using a pragma to turn them off. You will recognize these extensions by the asterisk following the SSWF version availability such as in: 1.7.3 (*).

The following table gives the operators in priority order. Operators with a higher priority appears first in the table. A higher priority is used first in an expression without the need to use parenthesis for proper grouping.

For instance, in a + b * c, the compiler generates b * c and then adds a to the result.

When you use one or more operators with the same priority, it usually will apply the first operation first (the one most on the left). A few operators have a right priority such as the power operator. This means the last operation is executed first.

For instance, the expression a ** b ** c is equivalent to a ** (b ** c).

The SSWF Availability column also include a flag to mark operators which can be overloaded. To overload an operator, create a function with a name written in a string that is the operator that you want to overload. For instance, the additive operator for the integers is defined like this:

	intrinsic function "+" (l: Integer, r: Integer): Integer;

Note that if you define your own class and want to override an operator you cannot specify intrinsic. It will usually reference objects of the same class, though this is not a requirement since operator functions are automatically considered static.

Operator
Name
Priority Comments SSWF
Availability
<expr> --
post decrement
18 Decrement the expression by one. If the expression is a variable name, the content of the variable is decremented. The expression result is the expression value before it is decremented. Note that if the expression is not a variable or an object, then this operator has no effect. 1.7.3
<expr> ++
post increment
18 Increment the expression by one. If the expression is a variable name, the content of the variable is incremented. The expression result is the value before it is incremented. Note that if the expression is not a variable or an object, then this operator has no effect. 1.7.3
<expr> ( <params> )
function call
18 An expression followed by parenthesis becomes a function call. The expression needs to be resolved as an identifier naming a function. The function can be defined locally, globally or as a class member. If the name is resolved as a variable name being a reference to an object of a class that has the "()" operator overloaded, then that operator function is called with this set to that variable. For example:
	class Foo {
		...
		function "()" (q: Number)
		{
			...
		}
		...
	};
	...
	var t: Foo = new Foo;
	...
	t(53.2);	// calls the "()" function
			// this = t and q = 53.2
	...


The <params> defined between the parenthesis in this definition represents a list of expressions separated by commas and used as parameters to the function being called. This list can be empty. All functions should be defined with a prototype. This means the type and number of parameters that you can pass to a function are predetermined and need to match the prototype exactly. If one or more functions with the same name are found but none of them match the prototype, then the compiler fails.

If the call expression is defined in a function, that function is named the caller function. Similarly, the function being called is named the callee function. When the caller function has a rest (...) parameter, it can be passed down to the callee function using the rest keyword as in:

	function func(a, b, ...)
	{
		sub_func(a + 3, ...);
	}

This has the effect of passing all of the parameters specified after the first two (a and b in this example) to the function func() down to the function sub_func() (not available in 1.7.3, at least not yet .

SSWF supports the naming of parameters. This means you can write the name of each parameter followed by a colon and then an expression representing the value given to that parameter. This enables you to specify the parameters in whatever order you like. Contrary to the ECMAScript documentation, in SSWF, you do not need to specify 'named' for any of the function parameters, you do not need to specify all the parameters by name even after you started to use a named parameter, and you do not need to have default values for any parameter in the function prototype. The compiler can very easily figure all of that out by itself.
1.7.3
overload
<expr> ( <expr> )
implicit cast
18 An expression followed by parenthesis becomes a cast whenever the expression represents a type. This has the effect of the as operator. For example:
	var a:Integer := Integer(x);
is equivalent to
	var a:Integer := x as Integer;
1.7.3
overload
<expr> [ ... ]
array or property access
18 The first expression is expected to be either an array or an object. In the first case, you can define a list of expressions between the square brackets ([]). When an object is being accessed, only one expression is expected which will be a string representing the name of a property of that object. 1.7.3
<expr> . <expr>
member
18 The period is used to access a member of an object or a package. This is considered an operator thought at times it does not really look like it. The second expression is usally an identifier, but it is not a requirement (Javascript is very dynamic!). When it is not an identifier the result will only be known at run time. 1.7.3
<expr> :: <expr>
scope
18 The scope is a way to group functions, variables and classes which can then dynamically be selected. It is somewhat similar to using a preprocessor in C/C++. The first expression is the name of the scope. The expression on the right is the name of the function, variable or class to access. Internally, there are many different scopes defined such as public, private, internal, protected, intrinsic, true, false, etc. Please, see the chapter Namespace & Scope for more information. Only some internal scopes are currently implemented. If it looks like there is a need for a real scoping support, I will look into add that in the language. It could be of interest in a world such as a browser so you can scope using the name of the browser (i.e. the same name function could be scoped for Netscape, Internet Explorer or Opera. Put that name in a variable, and the language automatically picks the correct function at run time!) n.a.
( <expr> )
grouping
17 Group expressions to force the order in which they need to be evaluated. In most cases, you can define a list of expressions between parenthesis. Note that an identifier used between parenthesis automatically becomes a reference to a variable whereas, used directly, it can be a direct name (i.e. a.b(); b is a direct member name, wheras in a.(b)(); b is viewed as a variable name or a getter function and what it returns becomes the member name.) 1.7.3
+ <expr>
positive
17 The positive operator is mainly for completeness. It may be used to convert any expression to a Number. However, you should really use the ToNumber() function for that purpose. 1.7.3
overload
- <expr>
negative
17 Negates the expression. This is equivalent to 0 - <expr>. 1.7.3
overload
~ <expr>
bitwise not
17 Transforms all the bits of the number from 1 to 0 and vice versa. This is similar to <expr> ^ -1 1.7.3
overload
! <expr>
logical not
17 If the expression is true, return false otherwise return true. 1.7.3
overload
-- <expr>
pre decrement
17 Decrements the expression by one. If the expression is a variable name, the content of the variable is decremented. The expression result is the decremented value. 1.7.3
++ <expr>
pre increment
17 Increments the expression by one. If the expression is a variable name, the content of the variable is incremented. The expression result is the incremented value. 1.7.3
new <expr> ( ... )
create an object
17 Creates a new object. The expression defines the name of a class of which an object is to be created. The result is a reference to the newly created object. You can later use that reference to call function members and read/write variable members of that object. The expression can be a function call. In that case a corresponding constructor will be called before the new expression returns. Note that the parenthesis are not required if there is not a constructor requiring parameters. You can create a copy of an object using the source object as a parameter to the constructor as in:
	o:Object;
	o := new Object;
	...
	copy:Object;
	copy := new Object(o);

NOTE: Some objects, in a Flash movie, cannot be created using the new operator. Instead, you need to call a specialized function which will automatically attach the object where it needs to be (i.e. a text field).
1.7.3
delete <expr>
destroy an object
17 Destroys an object previously created with the new operator. The expression is a reference to the object. 1.7.3
typeof <expr>
type of
17 Returns the type of the expression as a string. You can use this string to create another object of the same type, compare the type of two different objects, ensure that an object is of a specific type, etc. 1.7.3
void <expr>
void
17 Transforms the result of expression to void (that is undefined). This is similar to a cast. I am not too sure why we need this cast since you could put undefined in your expression as is if need be. Note: SSWF tries to optimize many things and this one is one of them. When SSWF finds a void, it first checks to see whether the expression has a side effect, if not, then the whole expression is simply replaced by undefined. This can be wrong if one of the parameters in the expression is a getter or some operators used have some hidden side effects. To fix this problem: do not use void 1.7.3
{ <name1>: <expr1>,
  <name2>: <expr2>,
    ...
  <namen>: <exprn> }

object declaration
17 Declares the list of members for a new object with the members separated by commas (,). Each member is defined as a name and a value separated by a colon (:). The name can be any dynamic expression resulting either in a string or a number. Putting a direct name as an identifier is view as a static name unless you put that identifier between parenthesis.

	var array = { a: 1, b: 2 };
Create an object with two members: a and b set to 1 and 2 respectively.

	var array = { (a): 1, (b): 2 };
In this case, a and b are viewed as variables and they need to be defined. Say a is set to first and b to second, then the new object will have two members: first and second set to 1 and 2 respectively as in:
	array.first = 1;
	array.second = 2;
1.7.3
[<expr1>, <expr2>, ... <exprn>]
array declaration
17 Creates an array from the list of items specified between square brackets and separated by commas. 1.7.3
function ...
function
17 Declares a function as a literal. The main purpose of this syntax is to create dynamic functions that you can attach to an object as a function member. Functions can also be saved in variables and later called with a syntax such as (func)(...).

Note: The dynamism of Flash is limited and all the possibilities that this syntax opens will actually not be available to you. Especially, the function must be constant at compile time to be used in Flash.
1.7.3
<expr> ** <expr>
power
16
right
Returns the first expression to the power of the second expression. Note that this operator has a right priority. 1.7.3
overload
<expr> * <expr>
multiply
15 Returns the multiplication of both expressions. 1.7.3
overload
<expr> / <expr>
divide
15 Returns the division of the first expression by the second. When both expressions are integers, then integer arthimetic is used. Otherwise it will compute a floating point value. If the second expression is zero, the expression will throw an exception. 1.7.3
overload
<expr> % <expr>
modulo
15 Returns the modulo of the first expression by the second. When both expressions are integers, then integer arthimetic is used. Otherwise it will compute a floating point value. If the second expression is zero, the expression will throw an exception. 1.7.3
overload
<expr> + <expr>
add
14 Returns the addition of both expressions. When both expressions are strings, the result is the concatenation of both strings. Otherwise the operator, like the other arithmetic operators, will try to convert both expressions to a number. 1.7.3
overload
<expr> - <expr>
subtract
14 Returns the first expression minus the second. 1.7.3
overload
<expr> << <expr>
shift left
13 Shifts the first expression on the left a number of bits as specified in the second expression. 1.7.3
overload
<expr> >> <expr>
shift right
13 Shifts the first expression on the right arithmetically a number of bits as specified in the second expression. This means the sign is being copied and thus negative values remain negative. 1.7.3
overload
<expr> >>> <expr>
unsigned shift right
13 Shifts the first expression on the right logically a number of bits as specified in the second expression. This means the sign is ignored and zeroes are pushed in as the shift is applied. 1.7.3
overload
<expr> !> <expr>
rotate right
13 Rotates the first expression on the right a number of bits as specified in the second expression. 1.7.3 (*)
overload
<expr> !< <expr>
rotate left
13 Rotates the first expression on the left a number of bits as specified in the second expression. 1.7.3 (*)
overload
<expr> < <expr>
less
12 Evaluates both expressions and compare them together. If the first expression is less than the second, the operator returns true, otherwise it returns false. 1.7.3
overload
<expr> > <expr>
greater
12 Evaluates both expressions and compare them together. If the first expression is greater than the second, the operator returns true, otherwise it returns false. 1.7.3
overload
<expr> <= <expr>
less or equal
12 Evaluates both expressions and compare them together. If the first expression is less or equal to the second, the operator returns true, otherwise it returns false. 1.7.3
overload
<expr> >= <expr>
greater or equal
12 Evaluates both expressions and compare them together. If the first expression is greater or equal to the second, the operator returns true, otherwise it returns false. 1.7.3
overload
<expr> is <expr>
is
12 Evaluates both expressions and determines whether the object on the left is of the type defined on the right.

Note 1: this is very similar to instanceof and it is implemented that way in SSWF for now. If you find a specific case where it should & could be distinguished, let me know!

Note 2: It looks like v8.x of Flash solves that problem with a new instruction (TBD) [maybe the isPrototypeOf()].
1.7.3
<expr> as <expr>
as
12 Casts the left hand side expression to the right hand side type. This expressions checks whether the expression defined on the left is of the right hand side type or one of its supers. If it is, then the left hand side object is returned. Otherwise, this expression returns null.

You can also write <expr>(<expr>) to cast the second expression (parameter) to some type (what looks like a function name.)
1.7.3
<expr> ~= <expr>
match
12 Test whether the first expression matches the regular expression defined in the second expression. [an internal implemention is available since Flash 9 with ABC ActionScript, which I do not support yet. Note that won't prevent an overloaded operator from working, but of course, you have to write the matching function...] n.a. (*)
overload
<expr> in <expr>
in property
12 The first expression is evaluated and expected to be the name of a property (also called member) to search in the object defined in the second expression. If it is found, this operator returns true, otherwise it returns false. WARNING: this syntax used in a for() has the effect of iterating through all the elements of the second expression, setting the variable defined as the first expression (which needs to be an identifier) 1.7.3
<expr> in <expr> ... <expr>
in range
12 Evaluates the first expression. Compare it against the second expression. If it is smaller, return false. Otherwise, evaluate the third expression. If it is larger, return false. Otherwise return true. In other words, test that the first expression is included between the bounds defined by the second and third expressions. Note that if the second expression is larger than the third, then this expression always returns false.

Note that at this time both the range (.. ) and rest (... ) operators are accepted as the range operator.
1.7.3 (*)
<expr> instanceof <expr>
object relationship
12 Defines the object type of the first expression and compare to the name of the class defined on the right. If both are equal, then return true. Note that equal means that the first expression is exactly of the type specified or is a derived class of the type specified in the second expression. For instance:
	class A { ... }
	class B extends A { ... };
	var b:B;
	b instanceof A === true
1.7.3
<expr> == <expr>
equal
11 Compares the two expressions and determine whether they are equal. If so, return true, otherwise return false. All objects can be compared between each others to know whether they are equal or not. You can also compare void values such as null and undefined. The equal and not equal operators are loose in the sense that many objects will be equal to null and undefined. The strictly equal and strictly not equal operators, however, will compare objects exactly. Thus, two objects need to be of exactly the same class to have a chance to be equal. 1.7.3
overload
<expr> === <expr>
strictly equal
11 Compares the two expressions and determines whether they are strictly equal. If so, return true, otherwise return false. Please, see the equal (==) operator for more information. 1.7.3
overload
<expr> != <expr>
<expr> <> <expr>
not equal
11 Compares the two expressions and determines whether they are different. If so, return true, otherwise return false. The <> operator is an extension and is available by default in SSWF. Macromedia supported that operator before and thus some people may still be used to it and since it does not break the syntax in anyway, it is still usable. Please, see the equal (==) operator for more information. 1.7.3 (*)
overload
<expr> !== <expr>
strictly not equal
11 Compares the two expressions and determines whether they are strictly different. If so, return true otherwise return false. Please, see the equal (==) operator for more information. 1.7.3
overload
<expr> & <expr>
bitwise and
10 Evaluates both expressions, and applies a bitwise and (keep all the bits which are set in both expressions). 1.7.3
overload
<expr> ^ <expr>
bitwise exclusive or
9 Evaluates both expressions, and applies a bitwise exclusive or (in the result, set all the bits which are not common to both expressions). 1.7.3
overload
<expr> | <expr>
bitwise or
8 Evaluates both expressions, and applies a bitwise or (keep all the bits which are set to 1 in both expressions). 1.7.3
overload
<expr> && <expr>
logical and
7 Evaluates both expressions, if both are true, returns true, otherwise returns false. 1.7.3
overload
<expr> ^^ <expr>
logical exclusive or
6 Evaluates both expressions, if both are equal, returns false, otherwise returns true.

This is partially an SSWF extension in the sense that it is not available in all Javascript implementations. However, because it is in the documentation of ECMAScript version 4, this implementation does not view this operator as an extension.
1.7.3
overload
<expr> || <expr>
logical or
5 Evaluates both expressions, if both are false, returns false, otherwise returns true. 1.7.3
overload
<expr> ?< <expr>
minimum
4 Evaluates both expressions and returns only the smallest one, the other is lost. Note that this operator is different from the Math.min() function since it works on numbers, strings, boolean and any other object which can be sorted (i.e. which has one of the minimum (?<) or less (<) operators overridden. But the use of the less operator is not yet implemented in 1.7.3) 1.7.3 (*)
overload
<expr> ?> <expr>
maximum
4 Evaluates both expressions and returns only the largest one, the other is lost. Note that this operator is different from the Math.max() function since it works on numbers, strings, booleans and any other object which can be sorted (i.e. which has one of the maximum (?>) or less (<) operators overridden. But the use of the less operator is not yet implemented in 1.7.3) 1.7.3 (*)
overload
<expr> ? <expr> : <expr>
conditional
3 Evaluates the first expression: (1) if true, evaluates the second expression and returns it, (2) if false, evaluates the third expression and returns it. Note that only one of the second or third expressions will be evaluated. This means if you have a function call in one of them, that function will be called only when that expression is required. The second and third expressions can usually be assignment expressions. However, in some cases they are limited to conditional expressions. 1.7.3
<expr> <assignment> <expr>
assignment
2
right
Assigns the expression on the right to the variable defined on the left. The available assignment operators are as described in the table below.

Note that all assignments have the same priority. The right most assignment is applied first. Note that implies that the expression on the right be evaluated first which is exactly what SSWF does. The expression on the left does not need to be an identifier, it can be a dynamically defined variable name (i.e. a string) in which case you want to mark the corresponding variables with the dynamic attribute.
Operator Comments Availability
= or := Sets the variable to the expression; the := is an SSWF extension (the set variable from Pascal) 1.7.3 (*)
+= Adds the expression to the variable 1.7.3
-= Subtracts the expression from the variable 1.7.3
&= In the variable, clears the bits that are zero (0) in the expression 1.7.3
|= In the variable, sets the bits that are set (1) in the expression 1.7.3
^= In the variable, swaps the bits that are set (1) in the expression 1.7.3
/= Divides the content of the variable by the expression 1.7.3
&&= Sets the variable to false, unless the variable and the expression are both true 1.7.3
||= Set the variable to true, unless the variable and the expression are both false 1.7.3
^^= Sets the variable to true, if the variable and the expression have different boolean values

NOTE: this is partially an SSWF extension in the sense that it is not available in all Javascript implementations. However, because it is in the documentation of ECMAScript version 4, this implementation does not view it as an extension.
1.7.3
?>= Sets the expression in the variable to the expression value if the expression is larger than the current value in the variable 1.7.3 (*)
?<= Sets the expression in the variable to the expression value if the expression is smaller than the current value in the variable 1.7.3 (*)
%= Computes the modulo of the variable content and the expression and saves the result in the variable 1.7.3
*= Multiplies the content of the variable by the expression and saves the result in the variable 1.7.3
**= Computes the content of the variable power the expression and saves the result in the variable 1.7.3 (*)
!>= Rotates the content of the variable by expression bits on the left 1.7.3 (*)
!<= Rotates the content of the variable by expression bits on the right 1.7.3 (*)
<<= Shifts the content of the variable by expression bits on the left 1.7.3
>>= Shifts the content of the variable by expression bits on the right keeping the sign (this is also called the arithmetic shift) 1.7.3
>>>= Shift the content of the variable by expression bits on the right not keeping the sign (zeroes are inserted in the top bits; this is also called a logical shift) 1.7.3
1.7.3
overload
<expr>, <expr>
list
1 Groups expressions one after another. The result is the last element of the list.

When used as a list of parameters, then each parameter is evaluated and each result is used for the corresponding function parameter. In that case, you can use a label to name the parameter that you are defining. Also, in a function that has a rest paramater (...) you can use ... to add all the arguments passed to your current function on to the next function.
1.7.3




Functions

SSWF supports an advanced function declaration and for evaluation it will always follow the ECMAScript specification in that it will evaluate the parameters from left to right. (Flash uses a stack and if you want to just follow the stack order, the parameters would be declared from right to left!)

A function is defined with a name, a list of parameters, a type and a body. The list of parameters is mandatory, though it can be empty or marked as unprototyped. However, you only need either a name or a body. Of course, you can also have everything defined. A function defined in an expression is expected to not have a name. A function defined anywhere else is required to have a name. The function type is optional and defaults to Object when not defined.

A function defined without a name is usually right away put in an object as a new function member. Then the name of the function is the name of the member. It can also be saved in a variable. Later you can use that variable to call the function.

A function defined without a body is either intrinsic (defined internally, also called implicit) or abstract. You cannot define an intrinsic function. These are defined in the Global, System and Native packages and cannot be extended without creating an external library for the Flash Player (and I think that only works under MS-Windows). Abstract functions can be defined in interfaces and classes. The last class to extend a class or interface with an abstract function needs to define that function if it is to be used. Note that Flash doesn't support abstract functions. Once compiled, these will simply have an empty body.

The declaration of a function goes like this:

	function [get|set] name ( param1, ... ) [: type] { ... }

Note that you can declare a function within another function. This works perfectly in SSWF and Flash. However, watch out because the size limit of a function is 64Kb in Flash. You may reach that size very quickly if you have many sub-functions.

It is possible to create a function named get or set (since Flash as such functions, we've got to support them!). When a function has the get or set keyword followed by another name, then the function is considered a getter or a setter. Note that Flash does not support that syntax. The compiler will generate the necessary code to simulate that functionality. Getters and setters can never be created dynamically.

The name of a function is any valid identifier or a string. In case of a string, it is expected to be an operator overload. (i.e. "+", "**", "<=", etc.) Note that like for getters and setters, Flash does not support operator overloading. The compiler will generate the necessary code for you. But this means you cannot use dynamic operator overloading; whenever you need dynamism, use functions.

The list of parameters defines what the function accepts as input. Flash works with a stack and thus the parameters would by default be defined from right to left. To avoid this problem, the SSWF compiler either computes the parameters and saves them in registers before to stack them, or it creates an array with the parameter values and passes that array instead. The array also allows for modifiable parameters (i.e. parameters marked 'out'). Each parameter can have attributes, a name, a type and a default value. The rest parameter (...) can only be named. It cannot receive a default value, nor any attributes. Note that the expression of the default value of parameter n can use the value of parameters 1 to n - 1 (ECMAScript version 5+ if I understand...).

The following shows the list of attributes that parameters accept in SSWF:

Attribute Comment SSWF
Availability
Void The parameter list is empty. Whenever you call this function you cannot specify any parameters. No other parameter can be specified with Void. 1.7.3
unprototyped A strange idea indeed... Defines the prototype as being whatever. It is also said to be unchecked. This means you can call this function with really anything you want. No other parameter can be specified with unprototyped. This, in effect, also prevents the function from being overloaded. 1.7.3
... Needs to be defined at the end of your function prototype. It tells the compiler that any parameter, which isn't explicitly defined, will actually be passed in an array of arguments. The rest can be given a name to be referenced in your function (so you can access the different parameters and pass them down to other functions), but no attribute and no default value. 1.7.3
const Mark the given parameter as constant. You cannot modify its value in the function. (This is usually not useful but it can prevent some bugs from happening.) 1.7.3
in This parameter is an input parameter. This means that the function expects the caller to define this parameter. This does not mean the parameter will be defined. Parameters can be in and out at the same time. This is the default for all the parameters. 1.7.3
var This really is noise. All parameters are variables. 1.7.3
out This parameter is an output parameter. This means the caller can expects the function to define this parameter thought there isn't really any garantee it will happen. Parameters can be in and out at the same time. The use of this attribute forces the compiler to use an array to pass all the parameters to this function. This is (very certainly) not compatible with other compilers. It was done that way because Flash does not support this attribute. 1.7.3
named This is noise. All the parameters have a name (don't they?!) and thus a function can always be called with labelled