EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Creating a Custom Object in Actionscript 1.0

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
794 Object-Oriented Programming with ActionScript 1.0
Creating a custom object in
ActionScript 1.0
To create a custom object, you define a constructor function. A constructor function is always
given the same name as the type of object it creates. You can use the keyword
this inside the
body of the constructor function to refer to the object that the constructor creates; when you
call a constructor function, Flash passes
this to the function as a hidden parameter. For
example, the following code is a constructor function that creates a circle with the property
radius:
function Circle(radius) {
this.radius = radius;
}
After you define the constructor function, you must create an instance of the object. Use the
new operator before the name of the constructor function, and assign a variable name to the
new instance. For example, the following code uses the
new operator to create a Circle object
with a radius of 5 and assigns it to the variable
myCircle:
myCircle = new Circle(5);
NOTE
Many Flash users can greatly benefit from using ActionScript 2.0, especially with
complex applications. For information on using ActionScript 2.0, see Chapter 7,
“Classes,” on page 225.
NOTE
An object has the same scope as the variable to which it is assigned.

Table of Contents

Related product manuals