Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

CheckBox label color changes in 0.9.2

In the 0.9.1 version of the SDK, this worked fine:

private

var notify_monday : CheckBox = new CheckBox();
this.notify_monday.label = 'Monday';
this.notify_monday.selected = true;
this.notify_monday.label_txt.textColor = 0xFFFFFF;
this.notify_monday.width = 200;
this.notify_monday.x     = 10;
this.notify_monday.y     = 35;
this.addChild( this.notify_monday );

 

And this set the label to white.  Now its either not showing the label at all (background is black) or it is black as well.  Anyone pick up what might have changed to get the label a different color for a CheckBox?

Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: CheckBox label color changes in 0.9.2

hey john,

 

its the strangest thing. there seems to be a bug. basically you need to use the setTextFormatForState(format, state); function to set the color and font for the label. in your case you would use the SkinStates.SELECTED state. so whenever the check box is in a "selected" state it is supposed to change the format to whatever you set it to using the method. however, its not doing that at all. it seems you need to add some extra code to force it to redraw the comonent in order to achieve a change of text format.

 

that being said here is the work around:

 

 

package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;
	import flash.text.TextFormat;
	
	import qnx.ui.buttons.CheckBox;
	import qnx.ui.skins.SkinStates;
	
	[SWF(width="1024", height="600", backgroundColor="#CCCCCC", frameRate="30")]
	public class CheckBoxTest extends Sprite
	{
		private var myCheckBox:CheckBox;
		
		public function CheckBoxTest()
		{
			super();
			
			// support autoOrients
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			var selectedFormat:TextFormat = new TextFormat("BBAlpha Sans", 16, 0xFFFFFF);
			
			myCheckBox = new CheckBox();
			
			
			myCheckBox.label = "Sample Text";
			myCheckBox.width = 200;
			myCheckBox.setPosition(10,35);
			myCheckBox.setTextFormatForState(selectedFormat, SkinStates.SELECTED);
			
			myCheckBox.addEventListener(MouseEvent.CLICK, onClick);
			
			
			addChild(myCheckBox);
			
			
		}
		
		private function onClick(e:MouseEvent):void
		{
			
			myCheckBox.width = myCheckBox.width;
	
		}
		
		
	}
}

 

 

So in the above code is the textformat of the checkbox object using the said setTextFormatForState() method. after that since it is not updating the color of the label after selecting and deselecting, i went ahead added a MouseEvent.CLICK listener and forced it to redraw by setting the width of the checkbox object. any attempts to change the size of a UIComponent will re-draw the object on to the stage. in doing so, it did the format properly. if you run the code you'll see its functioning.

 

we should have to do such a workaround but if we must we must right? so definitely a bug.

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Developer
studiochris
Posts: 165
Registered: ‎10-26-2010
My Device: BlackBerry® PlayBook™

Re: CheckBox label color changes in 0.9.2

[ Edited ]

The SDK examples and documentation don't show anything for a textcolor property. Everything shows using full TextFormat objects. According to the SDK, this is how you'd do what you've been doing:

 

 

private 
var notify_monday : CheckBox = new CheckBox();

private 
var myTextFormat : TextFormat = this.notify_monday.getTextFormatForState(SkinStates.UP);
myTextFormat.color = 0xFFFFFF;

this.notify_monday.setTextFormatForState(myTextFormat, SkinStates.UP);
this.notify_monday.setTextFormatForState(myTextFormat, SkinStates.DOWN);
this.notify_monday.setTextFormatForState(myTextFormat, SkinStates.SELECTED);
this.notify_monday.setTextFormatForState(myTextFormat, SkinStates.DISABLED);
this.notify_monday.setTextFormatForState(myTextFormat, SkinStates.DISABLED_SELECTED);

this.notify_monday.label = 'Monday';
this.notify_monday.selected = true;
this.notify_monday.width = 200;
this.notify_monday.x     = 10;
this.notify_monday.y     = 35;
this.addChild( this.notify_monday );

Edit: See that I was too slow for JRab and should probably refresh the screen before replying  :smileyvery-happy:

 

Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: CheckBox label color changes in 0.9.2

That seem to do it.  Good case for encapsulation.

Thanks to both.