Multiple Inheritance

From Director Online Wiki
Jump to: navigation, search

Multiple Inheritance is a advanced Object Oriented Programming principle that allows you to create more complex relationships between script - so that one script can inherit the attributes of several different ancestors.

Neither Lingo nor JavaScript support this feature as of now.

Probably this won't change, as this really is a very advanced programming feature and not really needed for the majority of Director-Applications.--ThomasSchmall


Nevertheless, there is a workaround.

Sprites use multiple inheritance by default. If you place two behaviors on a sprite, and both behaviors possess (say) a mouseUp handler, then a single #mouseUp event will cause two different chunks of code to execute.

Director is quite happy to let you set the ancestor of a script or instance to a sprite.

So, to provide an object with multiple inheritance, you need to attach two or more behaviors to a sprite, then set that sprite as the ancestor of the object. It is probably wise to keep the sprite off the Stage, and give it both a height and width of zero so that it does not interfere with any mouse or keyboard events in the movie.