Game Development Reference
In-Depth Information
Suppose you wanted to override a method and still call the parent's method; you
could do something like the following:
protected override function scan(delta:Number):void {
// Do something different here... and
// ... call the parent's method
super.scan(delta);
}
The super is another keyword and it always points to the current object's super class.
So you can call any method of the super class, but by invoking the method on
the super.
The reader is encouraged to create their own monster type by modifying the
previous code and using the subclassing technique.
Interface class
Another great concept from the object-oriented design is what is called the interface.
An interface is like a class, but with no variables. Instead is has only methods with
no implementation in them. You would simply define a bunch of method signatures
and give it a name similar to a class.
Flash Builder allows you to quickly create an interface similar to how you would
create a class. Right-click on the package that you want to create the interface in
and choose ActionScript Interface under the New menu item.
Here is an example declaration:
package world
{
public interface PhysicsItem
{
// ...
function getWeight():Number;
function updateVelocity(delta:Number):void;
function getSpeed():Number;
// ...
}
}
Note that all methods are by default public; you may not apply scoping attributes.
In order to have a class implement the interface, you must specify that the class
implements the interface and also provide concrete implementation for each of
the methods in the interface.
 
Search WWH ::




Custom Search