I am trying to override the text setter in the Label component but it behaves weirdly
sometime super.text works and sometimes not! and the traces show that there’s no error with my code.
here’s my code:
import spark.components.Label;
public class LabelXX extends Label
{
private var _initialText:String;
private var _assignedText:String;
public function LabelXX()
{
super();
}
override public function set text(value:String):void
{
if (!_initialText)
{
_initialText = value;
super.text = value;
trace("initial text = " + value);
}else
{
_assignedText = value;
super.text = _initialText + " " + _assignedText;
trace("Now: " + _initialText + " " + _assignedText);
}
//this wont have any effect no matter what I do:
//super.text = "test test test";
}
override public function get text():String
{
if (!_assignedText)
{
return "";
}else
{
return _assignedText;
}
}
}
UPDATE: if I comment the getter it works fine which still doesn’t make any sense!
thanks
Most likely the super get/set method are accessing some private variable that holds the value of the property. You’re extended class has no access to this private variable. By overriding the get method to never call super; while using it in the set method, you may experience oddities. Especially if anything in the parent is accessing the private variable and bypassing the get/set methods. It–sadly–happens occasionally in Flex Framework code. So, I might try to re-work your code to something like this: