First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
Search tutorials
Author: Nick Kuh (Webkuh) | Website:
You can create your own class containing initialised properties and then apply it to new objects which will inherit these from the class. Here is a simple example:
//first create the class:

function Human (name,sex) {
	//properties of the Human object = sex; = name;
	//objects contained within the Human which will hold their own properties 
	this.head = {};
	this.body = {};
	this.arms = {}
	this.legs = {};

Nick = new Human("Nick","male");
Nicole = new Human("Nicole","female");
trace("Nick is a "". Nicole is a "".");
A class is defined in ActionScript using the function method. It is good practice to capitalise classes to distinguish them from regular functions. In the example, we have made efficient use of ActionScript by defining the class just once and from then on new Human objects can be created by using one line of ActionScript. When an object is defined you can use either of the following methods to add properties to it:
this.head = {};
this.head.hairColour = 0x663399;
this.bigNose = true;


this.head = {hairColour : 0x663399, bigNose : true};
I prefer to use the second method. Add this to the Human class:
function Human (name,sex) { = name; = sex;
	this.head = {hairColour : 0x663399, bigNose : true};
	this.body = {};
	//introducing class methods
You'll notice that I've changed arms and legs in the Human class and added a new method call 'fReferers'. Here I'm calling methods of the Human class which will generate the arms and legs and a method which will create string references which I can use when dynamically creating sentences about my new male Human. Now to create the Human methods:
Human.prototype.fCreateArms = function (leftArmWaving,rightArmWaving) {
	this.arms = {};
	//short cut
	var sc = this.arms;
	sc.armLeft = { bWaving:leftArmWaving }
	sc.armRight = { bWaving:rightArmWaving }

Human.prototype.fReferers = function () {
	if( == "male") {
		this.referers = {n1 : "He", n2 : "His"};
		this.referers = {n1 : "She", n2 : "Her"};
You must use the prototype when creating class methods as it enables these methods to be called by any new object instance of the Human class.
» Level Intermediate

Added: 2002-10-29
Rating: 7 Votes: 36
(10 being the highest)
» Author
I am a Flash Developer with 3 years commercial experience programming database-driven games and applications. I am currently working on a contract job developing e-learning software for UK schools.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!


  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: work2survive
» Title: Girl Walking 1kb
» Description: Walking girl, animation just takes 1kb, using high heels shoes, and fashion model attitude.
Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.