Using Director > Behaviors > Example of a complete behavior

 

Example of a complete behavior

If the handlers described here were in one behavior, the script would look like this (the puppetSound command was added to the on mouseUp handler in this example):

property movement, noise

on getPropertyDescriptionList
	set description = [:]

	addProp description, #movement, [#default: 5, ¬
	#format:#integer, #comment: "Set motion to ¬
	the right:", #range: [#min:1, #max:10]]

	addProp description, #noise, [#default:"", ¬
	#format: #sound, #comment:"Sound cast ¬
	member name"]
	
	return description
end

on getBehaviorDescription
	return "This changes sprite color and position"
end

on mouseUp me
	set the foreColor of sprite the spriteNum of me ¬
	to random(255)
	puppetSound noise
end

on enterFrame me
	if the locH of sprite the spriteNum of me > ¬
	the stageRight then
		set the locH of sprite the spriteNum ¬
		of me = the stageLeft
	else
		set the locH of sprite the spriteNum of me to ¬
		(the locH of sprite the spriteNum of me + ¬ 
		movement)
	end if
end

When this behavior is attached to a sprite, each time the playback head enters a frame, the sprite moves to the right by the amount the user specifies. When the user clicks a sprite, its color changes and a specified sound plays.