PDA

View Full Version : How can i use more than one font, size or color on one line of text in AS3



spctom
March 26th, 2009, 08:53 PM
Hi Guys

I'm a noob, so please forgive me if i'm asking something really stupid!

I'm doing a group project and i've just got the code from someone else, so i can add my part.

I am trying to add text in actionscript 3 (in a actions frame) simple enough. but...
I want to have words next to each other, that have different fonts, font sizes and colors. I've been googling and experimenting for most of the day and haven't really got anywhere.

I will post what i have and what i would like to do, and if someone can help me, i would be most grateful.

Here the code that i'm working with:

//beginning of code
var info = infotext;
var infoFormat:TextFormat = new TextFormat();
infoFormat.color = 0x752D1A;
infoFormat.size = 14;
infoFormat.bold = "True";
infoFormat.font = "Comic Sans MS";
info.text = "Animal name : Kangaroo" + "\n" + "Animal type : Mammal" + "\n" + "Group name : Mob" + "\n" + "Babies name : Joey" + "\n" + "Diet : Grasses, Plants " + "\n" + "Habitat : Australian bush " + "\n" + "Life span : 12 - 23 Years" + "\n" + "Fact : A Kangaroo can hop at up to 40 mph";
info.setTextFormat(infoFormat);
info.wordWrap = true;
//end of code

When i first got the code, all that was there, was the info.text = "Animal...... line, i added the rest and also tried adding other line of code to make other words be in different fonts, but it didn't work.

So heres what i'm trying to do;

I would like to have the headings, example; Animal name, Animal Type.. in one font, and the answers, example; Kangaroo, Mammal in another font.
As it is at the moment, it look crap, because its all in the same font, color and size.

Can anyone help me please??? :ko:

Thank you in advance.

sebrofm
March 26th, 2009, 09:33 PM
var ss:StyleSheet = new StyleSheet();
ss.style("h", {fontFamily:"Arial", fontSize:"18"});
ss.style("p", {fontFamily:"Georgia", fontSize:"14"});

var info = new TextField();
info.styleSheet = ss;
info.multiline = true;
info.wordWrap = true;

into.htmlText = "<h>Animal Name: </h> <p>Kangaroo</p> <br> <h>Animal Type: </h> ..you get the point";

spctom
March 27th, 2009, 06:34 AM
Cheers for the help guys

I tried your example but it didn't work, but i did get this code to sort of work

myTextField.htmlText = '<font size="15" color="#ff0000">Animal Type:</font> <font size="12" color="#333999"> Kangaroo</font>';

but how do i change the font type and make some words bold, i have been playing around with the code myself but couldn't add font face or bold to this line of code to make it work

I would like Animal Type: to be bold and in verdana, and Kangaroo not to be bold but mybe in another font.

Can anyone help

Thanks for all the help guys