PDA

View Full Version : random text colour change



suha
May 15th, 2003, 04:59 AM
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.

2. is it possible to achieve?

3. is there any other alternative to implement this?

any help will be much appreciated.

m_andrews808
May 15th, 2003, 06:47 AM
do you want each individual word to be a different colour, or all words to be the same colour that changes with each scroll?

suha
May 15th, 2003, 07:01 AM
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.

m_andrews808
May 15th, 2003, 07:13 AM
okay, first put this in the first frame of the main timeline:



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):



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

suha
May 19th, 2003, 09:22 AM
would you please check my source file, its not working

m_andrews808
May 19th, 2003, 09:25 AM
okay, but you'll have to post your source file/code

suha
May 19th, 2003, 09:41 AM
i've tried to attach last time but didn't work. can i send it to you directly instead?

m_andrews808
May 19th, 2003, 09:42 AM
sure, send it to m_andrews808@hotmail.com

m_andrews808
May 19th, 2003, 10:12 AM
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?

suha
May 19th, 2003, 10:29 AM
it should only use the colour that specifed in the action script

m_andrews808
May 19th, 2003, 10:43 AM
check your mail