11-08-2010 08:00 PM
11-09-2010 02:45 PM
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.
/* 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;
If I submitted something helpful, please give me a kudo. Thanks.
11-09-2010 02:51 PM
11-09-2010 03:04 PM
11-09-2010 03:19 PM
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.
If my post was found to be helpful to you, please thank me with a Kudo. Thanks.
11-09-2010 03:30 PM
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.
11-09-2010 03:39 PM
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 );
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.
11-09-2010 03:55 PM
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.).
11-09-2010 07:44 PM
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.