简体   繁体   中英

How to change color of a textArea at runtime?

I am using a TextArea in my application, and wish to change the font color of textArea at runtime based on certain conditions? I am using the following code in a function

resultText.setStyle("color", 0x842D22). However, this does not work, and gives me an exception at runtime Cannot Access property of null object reference.

setStyle does not seem to work with textArea . please advise.

See if this example helps you:

  <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:Script> <![CDATA[ public var flag:Boolean = true; public function clickHandler():void{ if(flag) {resultText.setStyle("color","red"); } else { resultText.setStyle("color","blue"); } flag = !flag; } ]]> </mx:Script><mx:TextArea x="59" y="104" id="resultText"/> <mx:Button id="colorChangeButton" label="Change Color" click="clickHandler()" x="83" y="180" /></mx:Application> 

Try sharing code in case this doesnt help..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM