How do I Create a Color Picker Swatch?
This lesson will show you how to make a color picker swatch.
Create a Graphic
Select the Graphic tool (1) and draw a square graphic on a stack (2).
Make Graphic Opaque
Open the property inspector for the graphic and set the Opaque property to true.
Edit the Script
Open the script editor for the graphic and enter the script shown below.
The script uses the answer color dialog to display the system color picker (1). The backgroundcolor of the graphic is passed in as the default color to display in the color picker (2). The color the user selects is then assigned to the background color of the graphic (3).
Copy & Paste
on mouseUp pBtnNum
if pBtnNum is 1 then
## Prompt user for color using current color as default
answer color with the effective backgroundcolor of me
## If user didn't cancel then assign background color
## to chosen color
if the result is not "cancel" then
put it into theChosenColor
set the backgroundcolor of me to theChosenColor
The Script in Action
Switch to Run mode. Clicking on the graphic will now display the color picker.
Choose a new color and click OK.
The graphic is now assigned the new color.