Articles Archive
Articles Search
Director Wiki
 

Using Color Objects in Behaviors

August 22, 2001
by Will Turnage

When creating behaviors for your projects, one of the most powerful tools you have at your disposal is the #format property in the getPropertyDescriptionList handler. On a basic level, you can use it to specify specific data types like #string, #integer or #symbol, but you can also use value types like #marker, #bitmap, #script or #member to select specific information about your movie and use that in your behavior. However, in addition to the value types listed in Director's Help section, you can also use the #color value to specify color objects in your behaviors. Take this simple behavior for instance:

property pColor

on getPropertyDescriptionList

  return [#pColor: [#format: #color, #default: rgb ("#FFFFFF"), #comment: "Select a color:"]]

end

When you put this behavior on any sprite in your movie, this is the initial dialog box that pops up:

Here, you have the option to type in a specific color to store in a property inside your behavior. The only downside to this method is that you have to know all of the appropriate numbers for your red, green, and blue values. What if you just want to be able to look at the color and pick it that way? To do that, just click the OK button and dismiss this initial dialog box. Now, open your properties window and select the behaviors tab. It should look something like this:

Here, you can enter a hex string directly into the field area, or you have the option to click on the small box just to the left of the hex string. When you click on the box, then a color picker appears, like this:

Once the color picker appears, then you can select any color that you want, and when you're done, the color will be stored inside that instance of your behavior.

The possibilities are endless when it comes to using color objects in your behaviors. For instance, here's one example of a neat trick you can do that uses this code:

When you roll over each of the buttons across the bottom, that button changes the bgColor of the sprite at the top of the screen so that the specific color becomes invisible. The code for this is really simple too. In addition to the basic behavior code above, each button also has this handler on it:

on mouseEnter me

  sendAllSprites(#setBackgroundColor, pColor)

end

The final step is to place this code on a behavior on the sprite at the top of the screen.

on setBackgroundColor me, newColor

  sprite (me.spriteNum).bgColor = newColor

end

And that's all there is to it. A sample Director 8 movie is available for download in Mac or Windows format.

Will Turnage is a multimedia programmer based in New York City. In addition to his weekly role as Director Online's Multimedia Handyman, he is also the Technology Director for Sony Music's Client Side Technologies Group. You can read more about his work at http://will.turnage.com/.

Copyright 1997-2017, Director Online. Article content copyright by respective authors.