Date: Wed, 19 Nov 1997 01:25:12 -0800 From: Scott StruthersI think I figured out how to use ancestors for behaviors and thought others might find this useful or could help me find the holes in the approach.Subject: Exposing ancestor properties in behaviors
Objective: I want extensible base classes for behaviors. When child behaviors are used the parents properties should be appropriately exposed to the behavior inspector.
the problem was getting the ancestor's getPropertyDescription to send its list up to the behavior inspector when needed. To do this you need to create a temporary instance of the ancestor like so:
------------------ property ancestor on getPropertyDescriptionList me --get the ancestor's properties, add the childs properties, and return the list -- to the behavior inspector. set the ancestor of me = new(script "testParent") set theList = getPropertyDescriptionList(the ancestor of me) --add any child specific properties here. return theList end ------------------The behavior inspector then does something with the list and stashes your chosen property settings with the sprite as properties of the child. The original ancestor instance vanishes, and you are left with the problem of initializing the child behavior and its ancestors in beginSprite.
------------------ on beginSprite me set the ancestor of me = new(script "testParent") -- initialize the ancestor, but use my properties to do it callAncestor #beginSprite, me --beginSprite(ancestor) will initialize with ancestor properties which may not exist. You want the child's properties to be used. --add child specific initialization here. end ------------------Therefore, in the beginSprite you have to re-instantiate your ancestor. If the ancestor is a stand-alone behavior, you will probably need to make sure that it gets a beginSprite message itself. Careful that the ancestors beginSprite method is called with the child's instance, not the ancestors. You can also trap yourself in a nasty recursive loop if you accidently try to call the childs beginSprite instead of the ancestors.Don't forget that the ancestor behavior must have a "new" handler. It took me forever to figure out that I forgot one. The error message was that it couldn't find the parent script (although I was staring right at it).
If anyone see's any holes or improvements, please let me know.