Parts of an AS3 Class

This file introduces the parts of a normal AS3 class. In all likelihood you will not be working as a flash developer. However... there may come a time when you need to look at a file that's made in flash and its good to understand the concept of Classes as this is what all of Actionscript 3 is built on.

If it looks like a lot of bother, think of this as just introducing the concept and structure first - obviously scaffolding and structures aren't very much use, unless they are being used to build something specific. I find that I must build something before I can understand the structure of the file, so just try to keep these ideas in mind when building your AS3 projects and eventually the parts of an AS3 class will make more sense to you when you start building!

Flash
Create a new text box. Make it a dynamic text box and give it a name.



You will see this box in the center of the stage. It will be blank, but later it will have words innit!

TIP: Embed the font if you want to preserve the font over different computers



on the top frame add this code:

 var myName:Name = new Name; myName.SetFirstName("YourName"); myName.SetLastName("Here"); yourName.text = myName.GetFullName; 

Tip: Instead of using "myName.GetFullName;", why not try any other string in place of that?

Note that lots of these terms dont appear anywhere in the flash file. But the clue is in the "Name" class you have just invoked. Now we'll look at the Name class object that is being called when you declare a variable "var myName:Name"

Name.as
 package {

public class Name {		private var firstName:String; private var lastName:String;

function Name {

}

public function SetFirstName(anyValue:String):void {			firstName = anyValue; }

public function SetLastName(anyValue:String):void {			lastName = anyValue; }

public function GetFullName:String {

return firstName + " " + lastName;

}

}

} 

Explanation


First you have the Package



then you have the public class and its name



inside you can put the variables (private vars), constructor (function), and arguments (private functions)

What now?
You can use it in many different files! This same class can be used in other files without you having to edit them. Its like a stand alone object! Next we will look at Parallax...