as3 inherited variables – internal instead of private

So you read up on OOP’s you’ve had some experience with python, java, c++ sometime in the far distance past.
But what you got on your hands right now is ActionScript 3. I love as3. They tried to follow some form of standard, but certain things proper OOP nerds take for granted fell off the wayside.
Things like “Private”. Creating a singleton in flash required mind altering drugs for AS3.
And here is another classic that I stumbled into today when doing my own class for the first time in a while.
Inherit variables.

public class BaseStructure extends Sprite
{
private var aContainer:Array;
public function BaseStructre():void
{

}

function init():void
{
aContainer = new Array(1,2,3,4);
}
}

public class NewStructure extends BaseStructure
{
public function NewStructure():void
{

}

public function augmentStructure():void
{
aContainer.reverse();
}
}

my aim is to do the following.

var bob:NewStructure = NewStructure ();
bob.init();
bob.augmentStructure();

Sadly I can’t even get NewStructure to compile as aContainer just doesn’t exist in flashes little compiler brain. My brain screams it’s right there, It’s a private variable being inherited you mother fu#/%&#¤%¤#%.

However THE following compiles if you swap out private for internal.

public class BaseStructure extends Sprite
{
internal var aContainer:Array; // <= you see what I did there
public function BaseStructre():void
{

}

function init():void
{
aContainer = new Array(1,2,3,4);
}
}
And it all compiles.
Okay this is paraphrased from something I just did so if you copy and paste and it doesn’t work, don’t complain.

I’ve had the same problem and solution with overriding certain methods as well.
Chalk up another “weird” things under actionscripts poor handling of private.

0 Responses to “as3 inherited variables – internal instead of private”


Comments are currently closed.