AS3.0 Abstracts
Another thing I needed was a strict abstract class in AS3, again, public only constructors, and the absence of the "abstract" keyword from ActionScript meant a workaround.
Actionscript:
-
package
-
{
-
import flash.utils.getDefinitionByName;
-
import flash.utils.getQualifiedClassName;
-
-
public class AbstractExample
-
{
-
public function AbstractExample()
-
{
-
if( Class( getDefinitionByName( getQualifiedClassName( this ) ) ) == AbstractExample ) throw new Error( 'AbstractExample must be extended' );
-
-
// rest of constructor here...
-
}
-
}
-
}
I like this solution best as it doesn't rely on strings for comparison as in Tink's example. His method is shorter, and easier for typing. It's down to personal preference really.
1 Comment so far
Leave a reply
This method slowly :)
This method is much better:
package {import flash.utils.getQualifiedClassName;
[ExcludeClass]
public class AbstractClass {
public function AbstractClass() {
// super() here
if ((this as Object).constructor === AbstractClass) {
throw new ArgumentError('ArgumentError: '+getQualifiedClassName(this)+' class cannot be instantiated.');
}
}
}
}