Home > Products > Director > Support > Lingo, Behaviors and Parent Scripts Assigning ancestor properties to the child's parameter dialog box An ancestor's properties can be assigned in the dialog box that appears when a child behavior is dragged onto a sprite using the method described below. The list returned by the ancestor's getPropertyDescriptionList is propounded to the child's getPropertyDescriptionList . This allows child behaviors with different properties to inherit the ancestor's user interface for setting properties. Because the properties that are assigned by using the parameter dialog box are stored in the score along with a sprite, the ancestor's properties need to be copied to the ancestor (this is a limitation of Director 6). The solution is demonstrated in the utility function copyprops and the beginSprite handlers for the child behaviors, where copyprops is called. The example shown below consists of two ancestor scripts, two child scripts, and a movie script with the copyprops handler. Both child scripts assign an AncestorScript as their ancestor. Dragging a child script to a sprite demonstrates the addition of the ancestor's property widgets to the dialog box that appears at that time. Additionally, the two children modify their behavior at run time. ChildC changes its ancestor with the on MouseUp handler at run time. ChildB adds ChildC to the scriptInstanceList on MouseUp . The scriptInstanceList of a sprite is a list of all behaviors attached to the sprite. It can be changed only at run time. The ancestor script itself can be dragged to a sprite, as it implements its on MouseEnter handler, which is overridden by the child scripts. It is important to note that the new function is executed before beginSprite when a sprite is encountered by the playback head. An ancestor can implement beginSprite : but the ancestor's beginSprite handler will not be called unless it is explicitly called in the child's beginSprite handler using call #beginSprite , the ancestor of me, or if there is no beginSprite handler in the child script. It is also useful to note that handlers of a script (with the exception of movie scripts) can be called without the need for an instance of that script. For example: set p_list = getPropertyDescriptionList (script "AncestorScript") -- "in new ChildB" -- "beginSprite ChildB" -- "in copyprops" -- "ancestor: , count: 2" -- "AncestorVal2 30.0000" -- "AncestorVal 15.0000" -- "new ChildC" -- "beginsprite ChildC" -- "in copyprops" -- "ancestor: , count: 2" -- "AncestorVal2 30.0000" -- "AncestorVal 15.0000" -- "ChildBVal: 2.0000" -- "ancestor value: 15.0000" -- "ancestor value 2: 30.0000" -- "ChildCVal1: 1.0000" -- "ChildCVal2: 2.0000" -- "ancestor value: 15.0000" -- "ancestor value 2: 30.0000" -- "ChildCVal1: 1.0000" -- "ChildCVal2: 2.0000" -- "ancestor value: 15.0000" -- "ancestor value 2: 30.0000" -- "in new ChildB" -- "beginSprite ChildB" -- "in copyprops" -- "ancestor: , count: 2" -- "AncestorVal2 30.0000" -- "AncestorVal 15.0000" -- "new ChildC" -- "beginsprite ChildC" -- "in copyprops" -- "ancestor: , count: 2" -- "AncestorVal2 30.0000" -- "AncestorVal 15.0000" -- "ChildBVal: 2.0000" -- "ancestor value: 15.0000" -- "ancestor value 2: 30.0000" -- "ChildBVal: 2.0000" -- "ancestor value: 15.0000" -- "ancestor value 2: 30.0000" -- "in mouseUp childB" -- [] -- "new ChildC" -- "now: [, ]" -- "ChildCVal1: 1.0000" -- "ChildCVal2: 2.0000" -- "ancestor value: 15.0000" -- "ancestor value 2: 30.0000" -- "ChildBVal: 2.0000" -- "ancestor value: 15.0000" -- "ancestor value 2: 30.0000" -- "ChildCVal1: -1.0000" -- "ChildCVal2: -2.0000" -- "ancestor value: 10.0000" -- "ancestor value 2: 20.0000" -- "in mouseUp childB" -- [, ] -- "new ChildC" -- "now: [, , ]" -- "ChildCVal1: 1.0000" -- "ChildCVal2: 2.0000" -- "ancestorB value: -5.0000" -- "ChildCVal1: 1.0000" -- "ChildCVal2: 2.0000" -- "ancestorB value: -5.0000" Following is an example of a script that assigns both ancestor properties and child properties in the same dialog box. ------------------------------------------------------------------------ -- copyprops ------------------------------------------------------------------------ -- because the properties that are set as specified in the GetPropertyDescriptionList -- dialog box are recorded in the Score for the child object, the properties that -- belong to the ancestor must be copied up to the ancestor. This is a workaround -- necessary in this release. -- a very useful feature is the capability to examine and set properties of objects (script -- references) using getPropAt and SetAProp where the 'list' parameter can be the object. -- -- in this case the list of properties belonging to the ancestor is examined and the -- values for those properties are copied from the child to the ancestor. on copyProps me putx "in copyprops" set ancestorproplist = [] set ancestorproplist = the ancestor of me set i = count (ancestorproplist) putx "ancestor:" && ancestorproplist && ", count:" && i repeat while i > 0 set x = getPropAt(ancestorproplist, i) set val = getAProp (me, x) if val <> VOID then setAProp (ancestorproplist, x, val) putx x && val end if set i = i - 1 end repeat end --override debugging info by commenting out the put line. on putx s put s end ------------------------------------------------------------------------ -- childc ------------------------------------------------------------------------ property ancestor property childCVal1 property childCVal2 on new me set childCVal1 = -1.0 set childCVal2 = -2.0 putx "new ChildC" set the ancestor of me = new (script "AncestorScript") return me end on beginsprite me putx "beginsprite ChildC" copyProps me end on mouseEnter me reportvalue me end on mouseUp me setAncestorB me end on reportvalue me putx "ChildCVal1:" && the childCVal1 of me putx "ChildCVal2:" && the childCVal2 of me call (#report, the ancestor of me) end -- here is an example of changing the ancestor at run time, -- that shows ancestor variables can be changed within the child. on setAncestorB me set the ancestor of me = VOID set the ancestor of me = new (script "AncestorB") set the ancestorBval of me = -5.0 end on getPropertyDescriptionList me set p_list = [:] set p_list = getPropertyDescriptionList (script "AncestorScript") addprop p_list, #childCVal1, [ #comment: "Child C value:",#format:#float, #default: 1.0] addprop p_list, #childCVal2, [ #comment: "Child C value 2:",#format:#float, #default: 2.0] return p_list end ------------------------------------------------------------------------ -- AncestorB ------------------------------------------------------------------------ property AncestorBVal on new me set AncestorBVal = 100.0 return me end on report me put "ancestorB value:" && the AncestorBVal of me end on mouseEnter me putx "in Ancestor MouseEnter" report me end -- this handler defines the authortime user interface for the ancestor, -- values set here override those in the new handler, -- because the child calls copyProps after the new handler when assigning this -- as the ancestor. on getPropertyDescriptionList me set p_list = [ #AncestorBVal: [ #comment: "value:",#format:#float, #default: 15.0]] return p_list end ------------------------------------------------------------------------ -- AncestorScript ------------------------------------------------------------------------ -- here are some properties for the ancestor script property AncestorVal property AncestorVal2 -- the ancestor script needs a new handles, which will be called when the child -- instances an ancestor and assigns the returned value to be its ancestor on new me, channel set AncestorVal = 10.0 set AncestorVal2 = 20.0 return me end -- here is a handler that accesses properties of the ancestor on report me put "ancestor value:" && the AncestorVal of me put "ancestor value 2:" && the AncestorVal2 of me end -- here is a handler that can be overridden by the children -- note that the ancestor behavior can be dragged to a sprite and used as is on mouseEnter me putx "in Ancestor MouseEnter" report me end -- this handler defines the authortime user interface for the ancestor -- values set here override those in the new handler, -- because the child calls copyProps after the new handler when assigning this -- as the ancestor. on getPropertyDescriptionList me set p_list = [#AncestorVal: [ #comment: "value:",#format:#float, #default:15.0],#AncestorVal2: [#comment: "value2:",#format: #float, #default: 30.0]] return p_list end ------------------------------------------------------------------------ -- ChildB ------------------------------------------------------------------------ -- the ancestor property is going to be set in the new script -- the childBval is a child property that is set in the authortime UI property ancestor property childBVal on new me putx "in new ChildB" -- the new handler is always called before the beginsprite -- here the ancestor script is instanced and assigned to be the ancestor set the ancestor of me = new (script "AncestorScript") return me end on beginsprite me put "beginSprite ChildB" -- copyprops is necessary to copy the ancestors properties into the ancestor -- see copyprops for why this is necessary copyprops me end -- the mouseEnter handler will eat the MouseEnter event and the ancestor will not -- execute its mouseEnter handler on mouseEnter me reportvalue me end on reportvalue me put "ChildBVal:" && the childBVal of me call (#report, the ancestor of me) end on getPropertyDescriptionList me set p_list = [:] set p_list = getPropertyDescriptionList (script "AncestorScript") addprop p_list, #childBVal, [ #comment: "Child B value:",#format: #float, #default: 2.0] return p_list end on mouseUp me putx "in mouseUp childB" putx the scriptInstanceList of sprite the spritenum of me set newref = new (script "childC") add (the scriptInstanceList of sprite the spritenum of me, newref) putx "now:"&&the scriptInstanceList of sprite the spritenum of me end ------ -- end of file ------- Ê Ê -- /////////////////////////////////////////////////////////////////////////// -- "in new ChildB" -- "beginSprite ChildB" -- "in copyprops" -- "ancestor: , count: 2" -- "AncestorVal2 2.0000" -- "AncestorVal 1.0000" -- "new ChildC" -- "beginsprite ChildC" -- "in copyprops" -- "ancestor: , count: 2" -- "AncestorVal2 5.0000" -- "AncestorVal 4.0000" -- "ChildBVal: 3.0000" -- "ancestor value: 1.0000" -- "ancestor value 2: 2.0000" -- "in mouseUp childB" -- [] -- "new ChildC" -- "now: [, ]" -- "ChildCVal1: 6.0000" -- "ChildCVal2: 7.0000" -- "ancestor value: 4.0000" -- "ancestor value 2: 5.0000" -- "ChildCVal1: 6.0000" -- "ChildCVal2: 7.0000" -- "ancestorB value: -5.0000" -- "ChildCVal1: 6.0000" -- "ChildCVal2: 7.0000" -- "ancestorB value: -5.0000" -- "in Ancestor MouseEnter" -- "ancestorB value: 99.0000" -- "in Ancestor MouseEnter" -- "ancestorB value: 99.0000" -- "ChildBVal: 3.0000" -- "ancestor value: 1.0000" -- "ancestor value 2: 2.0000" -- "ChildCVal1: -1.0000" -- "ChildCVal2: -2.0000" -- "ancestor value: 10.0000" -- "ancestor value 2: 20.0000" -- "in mouseUp childB" -- [, ] -- "new ChildC" -- "now: [, , ]" -- "in mouseUp childB" -- [, , ] -- "new ChildC" -- "now: [, , , ]" -- "ChildBVal: 3.0000" -- "ancestor value: 1.0000" -- "ancestor value 2: 2.0000" -- "ChildCVal1: -1.0000" -- "ChildCVal2: -2.0000" -- "ancestorB value: -5.0000" -- "ChildCVal1: -1.0000" -- "ChildCVal2: -2.0000" -- "ancestorB value: -5.0000" -- "ChildCVal1: -1.0000" -- "ChildCVal2: -2.0000" -- "ancestor value: 10.0000" -- "ancestor value 2: 20.0000" -- //////////////////////////////////// -- FBC notes call (#report, the ancestor of me) is an important example