Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change font colour in textfield 1

Status
Not open for further replies.

ThomasJSmart

Programmer
Sep 16, 2002
634
Hi

I have an input field in flash with HTML enabled. this field contains text that can be orange or green, the contents is loaded dynamically and the colour is set via html with php before being loaded in. this works fine.

what i would like now and for which i would realy apreciate help :) is that when the user enters text into a field the newly entered text is coloured green. Any text already in the field which is not replaced should also be turned green, It should only make it green once the user enteres something, not if the field is just focussed.

Thanks!
Thomas



I learned a bit yesterday, today i learned a lot, imagine what i'll learn tomorrow!
 
Monitor the text using "onEnterFrame". If the text is changed from the original, setTextFormat and setNewTextFormat with green colour. This will change the existing text and newly input text into green.

Do you need a code example?

Kenneth Kawamoto
 
that would indeed work, but isnt using an enterframe script for 100 textfields a bit heavy on the resources?


I learned a bit yesterday, today i learned a lot, imagine what i'll learn tomorrow!
 
ok, this sounds much better. i would need to make a function for each field tho right?

textfield1.onChange = function(){
make text green
}

textfield2.onChange = function(){
make text green
}



any way these could be generated in some kind of loop?
something like this maybe?


for(i=1; i<100; i++){
obj = eval ('textfield'+i);

obj.onChange = function(){
make text green
}
}


i'll be at the office in another hour or 2 then i can try some things.




I learned a bit yesterday, today i learned a lot, imagine what i'll learn tomorrow!
 
Something along these lines:
Code:
var tfmt:TextFormat = new TextFormat();
with (tfmt) {
	color = 0x009900;
}
for (var i = 1; i<=100; i++) {
	this["textField"+i].onChanged = function():Void  {
		makeTextGreen(this);
	};
}
function makeTextGreen(tf:TextField):Void {
	tf.setTextFormat(tfmt);
}

Kenneth Kawamoto
 
hehe can you tell im actually a php programmer ^^
this works great :) nice function.
Thank you very much!



I learned a bit yesterday, today i learned a lot, imagine what i'll learn tomorrow!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top