Creating Objects in JavaScript
There are several ways to create objects in JavaScript. Traditionally this was done by creating instances of the function object using the 'new' keyword. A somewhat easier method is to create an 'object literal' which we'll also touch on below.
Creating Objects With Functions
If you're use to creating objects in object-oriented languages like Java, then you're in luck-this will at least seem (superficially) familiar.
The first thing that we'll do is create a function called 'PointObject'. Even though you can call this PointObject function in a standard procedural fashion-what we'll be using it for is to act as a template for other variables. From the perspective of object-oriented programming, you can think of what we're doing as setting up a 'class'.
function PointObject()
{
}
var Point;
Point = new PointObject();
Next we'll create a variable 'Point'. We set this Point variable equal to a new instance of the PointObject function. The act of creating a new instance actually calls the function itself.
Since the PointObject function is called upon object creation, you can think of the code inside the PointObject function as the class's constructor.
Creating Object Literals
Using Javascript's built in object notation, you can easily create an object literal like so:
var Point = {
};
You'll notice there really isn't any object template or class-you're literally creating the instance of the object directly using the '{' and '}' characters.
This is the first in a series of articles on object-oriented JavaScript; next time we'll look at creating fields.
There have been a number of ways to do this over the years and over different versions of Flash, but the way to do this today is with FlashVars. What are FlashVars you ask? FlashVars is the name of a parameter that you can pass into your Flash movie, via the 'param' tag.