Latest News and Developments
In this example I want to make an instance of the object GenericObject() that is contained in the ‘generic.as’ file.
You will start by including the .as file that contains the class myGenericObject();
#include “Generic.as”;
1. To include this in your .fla file you need to use the ‘new’ command in Actionscript.
var myGenericObject:GenericObject = new GenericObject();
2. You can make a movieClip instance a member of a class by right-clicking it in your library and selecting “Linkage…”. Once the window is open select “Export for Actionscript” and enter in the class name in the input field labeled “AS 2.0 Class:”. Click “OK” and now your movieClip will be a member of that class.
Use “instance of”to indicate whether your object is a instance of a class.
trace (myGenericObject instance of GenericObject); // yeilds true
When using Classes in Actionscript it is important to understand the relationships between classes, namely inheritance and composition.
Inheritance is where one class inherites the properties of another class, such as the example below. Snowboarding and surfing are both types of extreme sports and inherit properties such as being fast-paced and dangerous.
Composition is when one class is contained inside another class. For example, the class ‘person’ may contain a class for ‘feet’ and one for ‘hands’.
My Flash Resource - A continually growing collection of tutorials, thoughts and interests of a Flash Animator and/or Developer.