Skip to main content
Participant
April 27, 2020
Question

Mudar de cor ao selecionar um botão

  • April 27, 2020
  • 1 reply
  • 450 views

É possivel criar um formulário onde eu possa atribuir uma área que mude de cor ao clicar?

Séria possivel ter uma lista de cores que eu possa escolher para aplicar naquela área?

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
April 27, 2020

Sure, you can do that with a button field. Do you mean that you want it to change from one color to another each time you click it, like a "traffic light" (red to yellow to green to red, etc.)?

erikkasAuthor
Participant
April 28, 2020

Yes, that's right. How can I do that?
I looked for tutorials on the Internet but I couldn't find them.

try67
Community Expert
Community Expert
April 28, 2020

Sure, here's an example. Create a button with a red (RGB 1,0,0) fill color and then set the following as its MouseUp JavaScript code:

 

var colors = [color.red, color.yellow, color.green];

for (var i=0; i<colors.length; i++) {
	if (color.equal(event.target.fillColor, colors[i])) {
		event.target.fillColor = (i==colors.length-1) ? colors[0] : colors[i+1];
		break;
	}
}

Each time you click it it will switch to the next color in the colors array, which can be as long as you wish.