Director allows the users to create custom behaviors that can be re-used in various movies, example, if we are working on 3D samples, instead of writing script to initialize the physics world for each new movie, we can write a behavior that takes the physics world parameters and initializes the world automatically.
The following are the Predefined handlers in Director for writing a behavior script.
- getBehaviorDescription
- getBehaviorTooltip
- getPropertyDescriptionList
- isOKToAttach
- runPropertyDialog
The getBehaviorDescription handler is used to provide the behavior description in the Behavior Inspector (BI).
Drag and Drop any existing behavior from the Library into your movie, select the sprite or frame that the behavior has been attached to and then open the BI (windows -> Behavior Inspector). The BI lists the Events, Actions and the Description of the selected Behavior.
on getBehaviorDescription( aScript )
tString1 = "DIRECTOR
TEXT ALERT" & RETURN & RETURN & \
"Enables the Director to alert
the User at the start of the movie " & \
"Any text member" & \
"" & RETURN & RETURN & \
"This independent behavior does
not require a trigger." & RETURN & RETURN & \
"ACTIONS AND THEIR REQUIRED
TRIGGERS:" & RETURN & \
"- None" & RETURN & RETURN & \
"PARAMETERS:" & RETURN & \
"- Text Message" & RETURN & RETURN & \
"PERMITTED SPRITE TYPES:" & RETURN & \
"- Text Members"
return(tString1)
end getBehaviorDescription
aScript is a reference to the script member and the getBehaviorDescription handler returns a string.
Open the library palette and make the mouse pointer hover over any of the behaviors, a tooltip appears, which describes the behavior. This tooltip can be set using the getBehaviorTooltip handler.
on getBehaviorToolTip(
aScript )
tString1 = "Alerts the user when the movies starts" & RETURN & RETURN
tString2 = "-" && "Type" && ":" && "Independent Action"
& RETURN
tString3 = "-" && "Dependencies" && ":" && "None" & RETURN
return(tString1 & tString2
& tString3)
end getBehaviorToolTip
aScript is a reference to the script member and the getBehaviorToolTip handler returns a string.
Take the example of creating a behavior to initialize the physics world, this behavior would be used in various movies with different requirement, hence instead of hardcoding the values of parameters such as restitution, gravity etc. we can make them the behavior parameter. The getPropertyDescriptionList provides the list of parameters their definitions and labels. The parameters are initialized in the parameter dialogue box which is invoked when the behavior is dragged and dropped on the score, further modification can be done to the parameter values by clicking on the behavior tab of the property inspector of the sprite to which the behavior is attached.
on getPropertyDescriptionList( aScript )
if the currentSpriteNum > 0 then
tGPDList = [:]
tGPDList[#pText] = [ #comment: "Enter Text", #format: #string, #default: "hello
world"]
return tGPDList
end if
end getPropertyDescriptionList
aScript is a reference to the script member and the getPropertyDescriptionList handler returns property list.
#default, #format, #comment and #range are used to assign values for the settings of the parameter, #range is optional
#default – The parameter’s default value
#format– The parameter’s type, it can be #integer #float #string #symbol #member #bitmap #filmloop #field #palette #picture #sound #button #shape #movie #digitalvideo #script #richtext #ole #transition #xtra #frame #marker #ink #boolean
#comment– A string that provides the label for the parameter in the Parameter Dialogue box.
#range– A range of values that can be assigned to the parameter. The range is specified in a linear list with several values or as a or as a minimum and maximum in the form of a property list: [#min: minValue, #max: maxValue].
isOKToAttach handler is used to check the type of sprite to which the behavior is being attached. Two types of sprites can be checked for in this handler, the #graphic includes all graphic cast members, such as shapes, bitmaps, digital video, text etc., and the #script indicates that the behavior should be attached to the script channel.
on isOKToAttach (me,
aSpriteType, aSpriteNum)
case aSpriteType of
#graphic:
return getPos([#field, #text], sprite(aSpriteNum).member.type)
<> 0
#script:
return
FALSE
end case
end
The above method enables the user to drop the behavior only on sprites of type field and text. The aSpriteType gives the type of sprite on which the behavior is being dropped on and aSpriteNum is the channel number of the sprite on which the behavior is dropped on. The handler either return a TRUE or FALSE. TRUE indicates that the behavior can be attached to the sprite and FALSE indicates that the behavior cannot be attached.
runPropertyDialog is used to overrides the behavior’s parameter’s values that was set in the Parameter dialog box.
on runPropertyDialog me,
currentInitializerList
--force
mass to 10
currentInitializerList.setaProp(#mass, 10)
--
force gravitationalConstant to 9.8
currentInitializerList.setaProp(#gravitationalConstant, 9.8)
return currentInitializerList
end
currentInitializerList, is a property list containing the current values of the parameters in the behavior. This handler assigns the mass and gravitationalConstant a constant values without displaying a dialog box.
The functionality of the behavior is implemented using the Private custom handlers.
property pText
on beginSprite( me )
me.alertUser()
end
on alertUser
alert pText
end alertUser
The above code snippet causes an alert to be displayed when the beginsprite method is called. Alternatively we can invoke the alert dialogue box, everytime the mouse is clicked on the sprite to which the behavior is attached as follows.
on mouseUp ( me )
me.alertUser()
end
In Order to create a behavior, open Director’s cast window, click on the ‘choose cast’ button, and select the ‘New Cast…’ option in the drop down menu, in the New Cast dialogue box, type in the name of the behavior and set the storage option as ‘external’. Save the external cast member as SimpleAlertBehaviour.cst.
property pText
on beginSprite( me )
me.alertUser()
end
--------------------------------------------------------------------------------
--Private
Custom Handlers-------------------------------------------------------
--------------------------------------------------------------------------------
on alertUser
alert pText
end alertUser
--------------------------------------------------------------------------------
--Predefined
Custom Handlers-------------------------------------------------------
--------------------------------------------------------------------------------
on isOKToAttach (me,
aSpriteType, aSpriteNum)
case aSpriteType of
#graphic:
return getPos([#field, #text], sprite(aSpriteNum).member.type)
<> 0
#script:
return
FALSE
end case
end
on getPropertyDescriptionList( aScript )
if the currentSpriteNum > 0 then
tGPDList = [:]
tGPDList[#pText] = [ #comment: "Enter Text", #format: #string, #default: "hello
world"]
return tGPDList
end if
end getPropertyDescriptionList
on getBehaviorToolTip(
aScript )
tString1 = "Displays an alert when the movie starts" & RETURN & RETURN
tString2 = "-" && "Type" && ":" && "Independent Action"
& RETURN
tString3 = "-" && "Dependencies" && ":" && "None" & RETURN
return(tString1 & tString2
& tString3)
end getBehaviorToolTip
on getBehaviorDescription(
aScript )
tString1 = "DIRECTOR TEXT ALERT" & RETURN & RETURN & \
"Enables
the Director to alert the User at the start of the movie " & \
"Any
text member" & \
"" & RETURN & RETURN & \
"This
independent behavior does not require a trigger." & RETURN & RETURN & \
"ACTIONS
AND THEIR REQUIRED TRIGGERS:" & RETURN & \
"-
None" & RETURN & RETURN & \
"PARAMETERS:" & RETURN & \
"- Text
Message" & RETURN & RETURN & \
"PERMITTED
SPRITE TYPES:" & RETURN & \
"- Text
Members"
return(tString1)
end getBehaviorDescription
Place the external cast file in the folder C:\Program Files\Adobe\Adobe Director 11\Configuration\Libs.
Open Director and place a text field on the sprite. Click on the Library and expand the Behavior tree. Drag and Drop the SimpleAlertBehavior on the Text and run the movie.
Feedback:
If you have any questions or comments concerning this article, please send me a message at srideviaishwariya@gmail.com
|