Posts Tagged ‘interface’

AS3 Classes and Interfaces Quicktip

Saturday, January 19th, 2008

Interfaces in AS3 are super useful for requiring classes to support a set of public methods, enabling other classes to communicate through the interface thereby abstracting the class itself. AS3 doesn’t natively support abstract classes so using Interfaces is a good replacement in some cases, but if you’ve never used an Interface before you probably wouldn’t know how to implement it. The docs help a little, showing you how to instantiate a class using an interface with the “implements” keyword, but doesn’t go much further:

public class myClass implements myInterface{
}

But what if you’d like to implement a class while extending another? Well, it’s simple once you know the syntax…

public class myClass extends baseClass implements myInterface {
}

This is a very quick and simple tip that took me a while to find online due to the fact Adobe doesn’t mention it. Such a simple thing should be in the help docs, but I guess adobe thinks that anyone trying to use Interfaces would already know the syntax! Well now you do.


Follow me on GitHub
Follow me on Google+
Follow me on Twitter