AS1 OOP: Custom Object Classes
by senocular
The new Keyword
The new keyword is nothing new. It’s been used a lot,
probably by you and definitely in this tutorial, already.
What new is, is an operator in Actionscript that initiates a
constructor function call to create an instance of a new
object of that constructor's class type with the definition
as specified in the constructor function itself.
So far, we’ve made new Objects, new Strings, new Numbers,
new Arrays and even just now, a new House. Each one of those
are class constructors in Flash. Object, String, Number,
Array – all constructors. House too, only House was a custom
made constructor while the others are all pre-defined in
Flash (residing in the _global object). Without the new
keyword, they’re just functions. With the new keyword,
they’re constructors creating instances of that class.
Note that in calling a constructor function with new, the
this scope in the constructor call references the new
instance being created and not the object calling the
function. Its with this that property values and methods can
be added to the new object. Also, when done, the constructor
automatically returns the this object so that it can be
assigned to whatever variable you are using to store the
object. There is no need to have a line such as return this;