My Flash Resource – New Ideas and News for Applying Flash to Complex Gaming Apps

Latest News and Developments

April 17, 2008

2 ways to Instantiate an Object into a Project

by @ 2:38 pm. Filed under Actionscript 2.0 OOP, Flash Articles

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

Inheritance VS Composition Class Model

by @ 2:37 pm. Filed under Actionscript 2.0 OOP, Flash Articles

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.

inheritance.jpg


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’.

composition.jpg

My Flash Resource - A continually growing collection of tutorials, thoughts and interests of a Flash Animator and/or Developer.

categories:

other:

New Feedburner Feed!


Feel free to syndicate.

Learning Material

Flash Resources:


Listed on BlogShares
  • Resources