PDA

View Full Version : text conditional coloring


stilltrying
09-03-2003, 08:39 AM
I'm trying to get several boxes (but let's start at just one) to change to one of three colors depending on their respective text input box' (but again starting at just one is probably best). i.e. if the value 1 is inputted then a seperate box changes color to yellow, if 2 is inputted then the box goes orange and if three is inputted then the box goes red. I just can't sort out the (probably very simple) actionscript.

jaybee
09-03-2003, 09:05 AM
to change the colour of a seperate mc do it like this:


//input_txt and target_mc on the same timeline
input_txt.onChanged = function() {
var c = new Color(target_mc);
switch(this.text) {
case "1":
c.setRGB(0xff0000);
break;

case "2":
c.setRGB(0xf8f8f8);
break;

case "3":
c.setRGB(0xffff00);
break
}
}

if you want to have the textfield nested within the same mc as the one that changes colour do this:


//input_txt and inner_mc both nested within box_mc
box_mc.input_txt.onChanged = function() {
var c = new Color(this._parent.inner_mc);
switch(this.text) {
case "1":
c.setRGB(0xff0000);
break;

case "2":
c.setRGB(0xf8f8f8);
break;

case "3":
c.setRGB(0xffff00);
break
}
}