# Random Color hex display

**URL:** https://forum.kirupa.com/t/random-color-hex-display/96981
**Category:** Uncategorized
**Created:** [December 16, 2003, 4:55am UTC](https://forum.kirupa.com/t/random-color-hex-display/96981 "2003-12-16T04:55:40Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![macneilslt](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@macneilslt](https://forum.kirupa.com/u/macneilslt)
#### Post date: [December 16, 2003, 4:55am UTC](https://forum.kirupa.com/t/random-color-hex-display/96981/1 "2003-12-16T04:55:40Z")

</div>

I have a button that changes the RBG of an object like this:  
[AS]  
on(release) {  
myColor = Math.round( Math.random()\*0xFFFFFF );  
myColoredObject = new Color (\_root.square);  
myColoredObject.setRGB(myColor);

}

[/AS]

how can i make it so it displays the hex number for the color in a dynamic text box?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 16, 2003, 5:02am UTC](https://forum.kirupa.com/t/random-color-hex-display/96981/2 "2003-12-16T05:02:45Z")

</div>

Here is something I made a long while back, it may be of some help to you…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 16, 2003, 5:09am UTC](https://forum.kirupa.com/t/random-color-hex-display/96981/3 "2003-12-16T05:09:38Z")

</div>

That’s perfect, thanks 🙂

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 16, 2003, 5:13am UTC](https://forum.kirupa.com/t/random-color-hex-display/96981/4 "2003-12-16T05:13:28Z")

</div>

```auto
on(release) {
	myColor = Math.round( Math.random()*0xFFFFFF );
	myColoredObject = new Color (_root.square);
	myColoredObject.setRGB(myColor);
	
	myColor = myColor.toString(16); // convert hex value to a hex string
	while (myColor.length < 6) myColor = "0"+myColor; // make sure the hex string has 6 characters
	_root.myTextbox.text = "color = #"+myColor; // set it to the textfield text
}

```

… dont know what lost’s example was, but theres one for ya 🙂 the myColor.toString(16) is the important part there.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 16, 2003, 5:24am UTC](https://forum.kirupa.com/t/random-color-hex-display/96981/5 "2003-12-16T05:24:56Z")

</div>

Yeah set… myColor.getRGB().toString(16) is the important part in my script.

My script was meant to be a random color generator that generated a random hex value and printed the RGB value too (for those programs that don’t have HEX ability and you need to know the seperate red green and blue values)

So it’s a little more than what was needed, but i’m tired, stressed, and on the verge of suicide, so I don’t have time to help much ☹
