Let’s talk about some basic Object Oriented programming (OOP) principles - modifiers. Although some modifiers are used often, especially access modifier (private, public, protected and internal), others are rarely used since they are not needed in most cases. With that said, we tend to forget them and end up never using them, even when they are needed.
I decided to create a useful one page summary that can be revisited every time you forget the different types of modifiers available in ActionScript 3.0.
To begin let’s split the modifiers into two groups;
- Access modifier – is a modifier that changes the visibility of a class or its members.
- AS 3.0 Modifiers - used to modify declarations of types and type members in AS.
| Access Modifier | AS 3.0 Modifier |
| public | dynamic |
| private | Final |
| protected | native |
| internal | override |
| static | |
| interface | |
| abstract * |
Access Modifiers
| Modifier | Used on | Meaning |
| private | var const function namespace |
Available to the object that declares it. |
| protected | var const function namespace |
Available to object that declares it and subclass. |
| public | var const function namespace |
Accessible to any object. |
| internal | var const function namespace |
Available to any object within the same package. |
AS 3.0 Modifiers
| Modifier | Used on | Meaning |
| dynamic | class | Properties can be added at runtime. |
| final | class function |
Cannot be subclassed. Cannot be overridden dynamically looked up. |
| native | class function |
Flash Player native code. Only signature. |
| override | function | Replaces an inherited method. |
| static | var const function |
Belongs to the class, not to instances of the class. |
| interface | class | Define a set of methods but not their implementation. |
| Abstract * | class | Class includes method with no implementation. To be overridden later by a subclass. |
* Keyword is not available
As default I highly recommend you to declare your objects as private unless you need to let other class access the object. The goal is to keep your object as abstracted as possible; making your code as loosely coupled to other objects, which will increase the re-usability of the objects.
When developing API’s in Action Script we design and choose from different modifiers, however when the wrong modifier is used the object can be misused and the objects become coupled to other objects.
Here’s my wish list for AS 4.0;
- Action Script supports the abstract modifier.
- Action Script support for static classes to insure they are not being created by creating an instance reference.
- Action Script allow the creation of Private class constructors.
There are many scripts out there to add these modifiers but many seem like a hack than an elegant solution. They basically help you enforce how the modifiers should act.
The only one that I see as a good solution, and not as somewhat of a hack is for creating Abstract methods and classes, here’s an example of how to create and implement;
package com.utils
{
import flash.errors.IllegalOperationError;
public class AbstractClass
{
public function AbstractClass(self:MyAbstractClass)
{
if(self != this)
{
throw new IllegalOperationError(”Abstract class did not receive reference to self. MyAbstractClass cannot be instantiated directly.”);
}
}
public function method(param:String):void
{
throw new IllegalOperationError(”abstract function must be overriden”);
}
}
}
And here’s how you would implement the class;
package com
{
public class MyImplementClass extends AbstractClass
{
public function MyImplementClass()
{
super(this);
}
public override function method():void
{
trace("Method");
}
}
}






