I have this very simple custom component made from two Shortcuts : _left and _right .
It should represent several types of points in the game: 1.2.3.4.5. 6
The last number (“6” in the above example) should be in bold if it has just changed (in the current round of the game), otherwise all numbers should look the same.
Also, the last number should be red or green (depending on whether it is a “bad” or “good” score).
Here is my source code for ScoreLabel.mxml:
<?xml version="1.0" encoding="utf-8"?> <s:HGroup xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" gap="0"> <fx:Script> <![CDATA[ public function setText(str:String, changed:Boolean=false):void { if (!changed) { _right.text = ''; _left.text = str; return; } var array:Array = str.split('.'); _right.text = array.pop(); _left.text = array.join('.') + '.'; } public function setColor(n:uint):void { _right.setStyle('color', n); trace('setColor: ' + n); } ]]> </fx:Script> <s:Label id="_left" width="100%" textAlign="right"/> <s:Label id="_right" width="25" fontWeight="bold" color="#006600"/> </s:HGroup>
My problem: when I call myLabel.setColor (0xFF0000); the text does not change to red, but remains in green by default - although I can see the trace in the debugger.
Any ideas please, why the color does not change?
I also know that I could modify the above component:
private var _color:uint; <s:Label id="_right" width="25" fontWeight="bold" color="{_color}"/>
and change this _color member, but I would prefer not to enter another data binding, because I will have a lot of ScoreLabel in my application:

(as you see above, all numbers are green - eventhough setColor (0xFF0000) was called 3 times).
source share