0
votes

I have a movieclip parent that has movieclip instances inside. However the movieclip parent extends a baseclass, and I would like to define one of the children by using instance name and defining from the base class.

for example, if there was a child with an instance name of "player" inside of the movieclip parent.

from the movieclip parent class you would just define it as

player
//or
this.player

but from the base class, this method would not work. How would I define it from the base class?

1

1 Answers

0
votes

You can define player in your base class, but you have to disable "Automatically declare stage instances" in your AS3 settings. When you have the option checked the compiler blindly tries to add all named instances as properties of the linked class. If you turn it off, you can control where those properties are actually defined. For this reason I always turn this feature off.

Example:

class Base extends MovieClip {
    public var player:MovieClip;
}

class SymbolClass extends Base {
    // linked to a symbol that contains a 'player' instance
}

If you have "Automatically declare stage instances" checked, you can't do this because SymbolClass will try to automatically declare player and it will conflict with the Base player declaration.

Also note that if your symbol does not contain a player instance, the code is still valid but player will be null.