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
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

CheckBox (and other controls) label font color change?

Has anyone had any luck in setting the font of a control to a different color?

 

In the control "Label" has an attribute "format" of the type TextFormat that has a "color" attribute, but it does not seen to do anything.  Same with size.

Developer
Posts: 110
Registered: ‎10-31-2010
My Device: Blackberry Torch 9800

Re: CheckBox (and other controls) label font color change?

Yeah, I had to fiddle with it a bit to figure out the hierarchy of all the classes... but here's a snipet that should work for you.

 

    import qnx.ui.text.Label;

 

            /* A label in which to show the hello greeting. */
            var helloLabel:Label = new Label();

            helloLabel = new Label();
            helloLabel.width = 800;
            helloLabel.height = 30;
            helloLabel.x = (stage.stageWidth - helloLabel.width) / 2;
            helloLabel.y = 60;
            
            var txtFormat:TextFormat = new TextFormat();
            txtFormat.align = TextFormatAlign.CENTER;
            txtFormat.font = "Arial";
            txtFormat.color = 0x103f10;
            txtFormat.size = 24;
            helloLabel.format = txtFormat;
            addChild(helloLabel);

 

 

Regards Brent

 

If I submitted something helpful, please give me a kudo.  Thanks.

Best regards,

Brent

If you found my post helpful, please thank me with a Kudo. Thanks!
Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: CheckBox (and other controls) label font color change?

Ah, no direct manipulation to the object.  Counter intuitive.

 

BB: Suggest the documentation be updated to reflext the issue (or better yet, allow for direct manipulation to cut down on the lines of code).

Developer
Posts: 274
Registered: ‎11-01-2010
My Device: PlayBook?

Re: CheckBox (and other controls) label font color change?

That's the way Actionscript handles everything, so I doubt they would change it and make it inconsistent.

Developer
Posts: 110
Registered: ‎10-31-2010
My Device: Blackberry Torch 9800

Re: CheckBox (and other controls) label font color change?

Yes, it seems strange that the QNX Label which seems to support:

 

            helloLabel.format.color = 0x103f10;
            helloLabel.format.align = TextFormatAlign.CENTER;
            helloLabel.format.font = "Arial";
            helloLabel.format.color = 0x103f10;
            helloLabel.format.size = 24;

wouldn't work in this fashion.  But I do notice that it doesn't have nearly the same class as the spark.components.Label or the old mx.components.Label (which wouldn't allow you to do the above anyway as they don't support the .format methods).     I had thought the qnx. classes were meant to be completely portable between spark and qnx (except for the import) but it doesn't appear that they are. 

 

Regards

 

Brent

 

If my post was found to be helpful to you, please thank me with a Kudo.  Thanks.

 

 

Best regards,

Brent

If you found my post helpful, please thank me with a Kudo. Thanks!
Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: CheckBox (and other controls) label font color change?

ActionScript as a language not not prevent direct manipulation of an object, the implementation of the class defines the behavior.  In this case, if the Label.format was not allocated (assumed), then allocating a TextFormat and setting it to format is required.  If Label allocated format in its construction, then direct manipulation of the format's attributes is possible.

 

Not the end of the world, just have to aware of it.  This is similar the adding columns to a DataGrid.  You cannot just push a new column to a DataGrid, you have to create your own array of columns, add them, and then set the DataGrids columns to this new array.

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

Re: CheckBox (and other controls) label font color change?

To be in violent agreement with you, at least you can manipulate MX styles individually, for example:

 

var label : Label = new Label();

label.setStyle( 'fontSize', 12 );

etc.

 

Now, I was never a big fan of meta driven style manipulation since is requires the developer to know them by heart (or look up in the documentation) instead of having the IDE (FB4) prompt you as your type.  I like that QNX Label has the format attribute, its just unfortunete that you can not just change one of its attributes without having to instantiate the whole format class.

 

Again, not the end of the world.  Just will extend to get the behavior I am looking for.

 

Developer
Posts: 110
Registered: ‎10-31-2010
My Device: Blackberry Torch 9800

Re: CheckBox (and other controls) label font color change?

Yeah, I would have thought that when you instantiated a Label class into its own object, you'd also end up with an "internal" TextFormat object but I guess they are trying to save space.  Of course the benefit to instantiating your own TextFormat class is that you can use that one instance for many different objects (Label 1, Label 2, Text 1, Text 2, etc.). 

Best regards,

Brent

If you found my post helpful, please thank me with a Kudo. Thanks!
New Developer
Posts: 21
Registered: ‎11-08-2010
My Device: Not Specified

Re: CheckBox (and other controls) label font color change?

I ran into the label formatting problems earlier today.  One way you can assign the formatting of a label is like this:

 

 

var label:Label = new Label();
label.format = new TextFormat(null, null, "0xFFFFFF");

 

 

You're using the regular AS3 TextFormat class, which has a constructor signature that looks like this:

 

 

TextFormat(font:String = null, size:Object = null, color:Object = null, bold:Object = null, italic:Object = null, underline:Object = null, url:String = null, target:String = null, align:String = null, leftMargin:Object = null, rightMargin:Object = null, indent:Object = null, leading:Object = null)

 

So in my example I'm keeping the default font and size, I'm just overriding the color to make it white.