我在我的应用程序中使用TextArea,并希望在运行时根据特定条件更改textArea的字体颜色?我在函数中使用以下代码如何在运行时更改textArea的颜色?
resultText.setStyle(“color”,0x842D22)。 但是,这不起作用,并在运行时给我一个例外 无法访问空对象引用的属性。
setStyle似乎不适用于textArea。请指教。
我在我的应用程序中使用TextArea,并希望在运行时根据特定条件更改textArea的字体颜色?我在函数中使用以下代码如何在运行时更改textArea的颜色?
resultText.setStyle(“color”,0x842D22)。 但是,这不起作用,并在运行时给我一个例外 无法访问空对象引用的属性。
setStyle似乎不适用于textArea。请指教。
看看这个例子可以帮助你:
<?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>
尝试的情况下,这并不帮助共享代码..
你可以使用setStyle方法resultText对象的其他属性?当您尝试使用它时,null对象引用可能指示resultText为null。也许你可以发布你遇到问题的方法的一个更大的片段。 – martineno 2010-11-22 08:16:57