# Random text colour change

**URL:** https://forum.kirupa.com/t/random-text-colour-change/20968
**Category:** Uncategorized
**Created:** [May 15, 2003, 8:59am UTC](https://forum.kirupa.com/t/random-text-colour-change/20968 "2003-05-15T08:59:04Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![suha](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@suha](https://forum.kirupa.com/u/suha)
#### Post date: [May 15, 2003, 8:59am UTC](https://forum.kirupa.com/t/random-text-colour-change/20968/1 "2003-05-15T08:59:04Z")

</div>

i’ve a movie clip (e.g. scroll\_text) which is consist of 5 words (each word is an individual movie clip). an instance of ‘scroll\_text’ movie clip placed in the main timeline with the following script:

onClipEvent (enterFrame) {  
\_x -= 30;  
if (\_x\<=-2247) {  
\_y = 40+Math.random()\*(400-40);  
\_x = 1024;  
}  
}

this script allows the movie clip to do the following:

1. scroll from right to left
2. start with a new ‘y’ coordinate for each new scroll
3. restrict the ‘y’ coordinate between 40 to 400

* * *

at the moment i’m trying to achieve the following:

1. i like to assign a specific colour value randomly to each word embedded in the ‘scroll\_text movieclip’. so for each new scroll each word will appear in a different colour. for example,

for the first scroll each word should display in following colour:

word 1: #ffffff  
word 2: #000000  
word 3: #33ff00  
word 4: #cc6699  
word 5: #666666

and for the next scroll it will just swap the colour between words. this should happen continuously.

1. is it possible to achieve?

2. is there any other alternative to implement this?

any help will be much appreciated.

---

<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: [May 15, 2003, 10:47am UTC](https://forum.kirupa.com/t/random-text-colour-change/20968/2 "2003-05-15T10:47:44Z")

</div>

do you want each individual word to be a different colour, or all words to be the same colour that changes with each scroll?

---

<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: [May 15, 2003, 11:01am UTC](https://forum.kirupa.com/t/random-text-colour-change/20968/3 "2003-05-15T11:01:43Z")

</div>

yes each word should display in different colour for each new scroll. so five words in one scroll should appear in five different colour as mentioned previous mail.

---

<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: [May 15, 2003, 11:13am UTC](https://forum.kirupa.com/t/random-text-colour-change/20968/4 "2003-05-15T11:13:08Z")

</div>

okay, first put this in the first frame of the main timeline:

```auto

function RandomColour() {
	Count = 0;
	ColString = "#";
	while(Count < 6) {
		Num = random(16);
		switch(Num) {
			case 10:
				Char = "A";
				break;
			case 11:
				Char = "B";
				break;
			case 12:
				Char = "C";
				break;
			case 13:
				Char = "D";
				break;
			case 14:
				Char = "E";
				break;
			case 15:
				Char = "F";
				break;
			default:
				Char = Num;
		}
		ColString += Char;
		++Count;
	}
	return ColString;
}

```

now at the start of each scroll, you’ll need this code (make sure the textfield your words appear in is html enabled):

```auto

Text = "<font color=\"" + _root.RandomColour() + "\">" + Word1 + "</font>" + "<font color=\"" + _root.RandomColour() + "\">" + Word2 + "</font>" + "<font color=\"" + _root.RandomColour() + "\">" + Word3 + "</font>" + "<font color=\"" + _root.RandomColour() + "\">" + Word4 + "</font>" + "<font color=\"" + _root.RandomColour() + "\">" + Word5 + "</font>";

```

should do the job, let me know how you get on

---

<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: [May 19, 2003, 1:22pm UTC](https://forum.kirupa.com/t/random-text-colour-change/20968/5 "2003-05-19T13:22:54Z")

</div>

would you please check my source file, its not working

---

<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: [May 19, 2003, 1:25pm UTC](https://forum.kirupa.com/t/random-text-colour-change/20968/6 "2003-05-19T13:25:30Z")

</div>

okay, but you’ll have to post your source file/code

---

<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: [May 19, 2003, 1:41pm UTC](https://forum.kirupa.com/t/random-text-colour-change/20968/7 "2003-05-19T13:41:38Z")

</div>

i’ve tried to attach last time but didn’t work. can i send it to you directly instead?

---

<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: [May 19, 2003, 1:42pm UTC](https://forum.kirupa.com/t/random-text-colour-change/20968/8 "2003-05-19T13:42:58Z")

</div>

sure, send it to [m\_andrews808@hotmail.com](mailto:m_andrews808@hotmail.com)

---

<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: [May 19, 2003, 2:12pm UTC](https://forum.kirupa.com/t/random-text-colour-change/20968/9 "2003-05-19T14:12:42Z")

</div>

I’m a bit confused by the fla you sent me, do you want each word to randomly pick a colour from a predefined selection of colours, or do you want each word to be a colour generated randomly?

---

<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: [May 19, 2003, 2:29pm UTC](https://forum.kirupa.com/t/random-text-colour-change/20968/10 "2003-05-19T14:29:53Z")

</div>

it should only use the colour that specifed in the action script

---

<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: [May 19, 2003, 2:43pm UTC](https://forum.kirupa.com/t/random-text-colour-change/20968/11 "2003-05-19T14:43:14Z")

</div>

check your mail
