ActionScript 2 hints

Hello everybody,

I took the liberty to sum up a few Hints, tips, pointers, facts, call them whatever you want, about Flash ActionScript 2.
This is the new ActionScript language, and it will raise alot of new questions here on the boards. Hopefully this thread will help out.

Please feel free to append as many tips as you want.

[list=1]
[*]When using classes, each individual class should be in their own file. (with .as extension).
This also goes for subclasses, (classes that extend another class)

[*]The filename of a class should be the same as the classname.
When creating a instance of your class, Flash looks for the filenames when compiling the .swf.

[*]When importing classes, the path should also be defined inside the class
So importing a class from a subfolder, the class should be defined like:

class subfolder.classname{}

[*]ActionScript 2 is Case Sensitive
Variables, Classes, Objects, Functions, they should all be indentified with the declared name. Case sensitive.

[*]ActionScript 1 is Case Sensitive
Although ActionScript 1 remains the same, it is case sensitive if the SWF is published with ActionScript 2 support.
So no more “movieclip.prototype”, cause the class movieclip is declared like “MovieClip”

[*]In classes, “this” refers the the instance, not to the class.
That means that “this” contains a different value in each instance, but as a property it behaves the same.

[*]Properties don’t require “this” in front of them.
When accessing Properties and Variables from a class, “this” isn’t required anymore, the var is recognized by the class.

[*]Constructors cannot have a return value.
When using constructor functions in a class, you cannot return a value. And if you use strict data typing:

function classname(): Void

will cause a compiler error aswell.

[*]Strict data typing is not required.
Just handy for the programmer! :p:

[*]Private vars are also accessible from subclasses.
Private vars and functions can be accessed from the class itself, or subclasses. You can even make a private var public from a subclass.

[*]"#include" inside a class adds the content to the body of that class.
It cannot be declared in a function though, it has to be in the body of the class.

[*]Properties should only be initialized in the constructor.

var valuelist: Array = new Array();

Does work, but Flash gets mixed up if you use multiple instances in one keyframe.

[*]Flash MX built in classes are NOT dynamic.
So extending Math like this doesn’t work anymore.

Math.afunction = function() { }

[*]Interfaces cannot contain properties.
Variables and properties should be declared in the Class Header.

[*]Interfaces can only provide static public functions.
You can’t define any dynamic functions in an interface.

[*]Get and Set aren’t allowed in interfaces.
Because they make a function behave as a property, they are not allowed in interfaces.

[*]Interface functions can also be in subclasses
Although all functions that are declared in an interface must be defined, they do not have to be inside the class, but the instance. This means those functions can also be inherited by a superclass.

[*]Interfaces can be object types.
The following example is allowed:

var instance: Interfacename = new Classname(); is allowed.

[*]Classes should operate independantly of the .swf.
Don’t specify “_root”, in a class, but set a parameter for the path instead. This is not required, but I’ve put this in because its a part of a class’ OOP interface.

[*]SetInterval only works on the instance, not on the class.
To add a interval to your instance, you need to give the instancename as a parameter to the SetInterval function.
Call the instance name with “this”, like so:

setInterval(this, "functioname", interval, [additional parameters]);

[*]ActionScript 2 works in the latest Flash 6 Player.
Just 10 till 30 percent slower :crazy:

[*]ActionScript 2 doesn’t get highlighted on the Kirupa Forums et.
:azn:

[*]Macromedia acknowledged that ActionScript 2 is for experience ActionScript programmers.
Don’t attempt to learn it, if you do not fully comprehend all the aspects of ActionScript 1.
[/list=1]

This turned out quite longer then I expected from myself.
Maybe this would make a nice STICK thread :slight_smile:

Many greetings, check my Review for more ActionScript 2 info
here.

Eric Jr - junioronline!!!

==========================================

For more on Actionscript 2.0, don’t forget to check out the Kirupa AS2.0 tutorial here:
[color=blue]http://www.kirupa.com/developer/oop2/AS2OOPindex.htm[/color]

and the Flash MX 2004 and ActionScript 2.0 Tutorials: The Definitive List here:
[color=blue]http://www.actionscripthero.com/adventures/index.php?c=2[/color]

Hmm. I never learned AS1. Would I suck at AS2 if I bought a book on it and studied it?

you would understand AS2 better knowing AS1, and really, AS2 is just an extension, or an alternate means of class creation for AS1. It replaces the methods used in OOP coding with AS1, though they still work when using AS2.

So learning AS2 is learning a part of AS, and if you get a book on AS2 that teaches not just AS2 but AS from a beginners level, then you wont miss much from not knowing how to do things (in OOP) the old fashioned way. You just have to make sure you have enough background to handle whatever is required for AS2 as said book intends to teach it.

You can not really use the new components with out at least compiling to AS2.

-Ken

The procedural programming in AS2 is very much like AS1. The OOP of AS2 in classes is pretty different then AS1 an in many ways more strait forward and similar to other programming languages. Any book you get on AS2 should cover what you need from AS1 before getting into the topics specific to AS2. If you don’t have a need to code specifically to Player 6 then you would be better off just diving right in.

Good luck!

-Ken

Ok thanks.

Anybody know of any good AS2 books?