Using Objects in ActionScript > Creating classes |
![]() ![]() ![]() |
Creating classes
To create a class, you use a constructor function. You assign properties for the class within the body of the function. To create a class that allows you to assign different property values to each object in the class, you define the constructor function to accept arguments for the assigned properties.
For example, here is a constructor for a class named Ball that accepts arguments for radius
, color
, and alpha
properties:
function Ball(radius, color, alpha){} this.radius = radius; this.color = color; this.alpha = alpha;
To make a class available to all movie clips in a movie, place the ActionScript code for the class in the first frame of the main movie Timeline.
For more information on creating custom functions, see Creating functions.
Note: You can also create a class that simply names the class and assigns properties, and does not accept arguments for properties. If you create a class that does not accept arguments, then every object in the class will have the same property values.
To create a class that accepts arguments for the assigned properties:
functionConstructor
(value1, value2, value3
){} this.property1 = value1; this.property2 = value2; this.property3 = value3;
![]() ![]() ![]() |