Showing posts with label css. Show all posts
Showing posts with label css. Show all posts

Monday, October 3, 2011

HTML tags in textfield

If you want to format text in field using old html tag here is simple list of possible tags:


  • <a> hyperlink. Has two parameters:
    • target - target window
    • href - url  (or event!)
  • <b> - text betwen those tags will be bold
  • <br> - breaks line
  • <font> - describes font:
    • color - color of the text. Must be in hex (with # at the begining)
    • face - font name
    • size - font size
  • <img>  allows to embed image (or swf) like in html site. Here is a list of supported properties:
    • src - source of media
    • width - width of rectangle where media is placed (always in px)
    • height - height of rectangle where media is placed (always in px)
    • align - horizontal alignment. Left or right. Specifies on which side text will flow around the image
    • hspace - horizontal margin around media. By default it is 8px
    • vspace - vertical margin around media. By default it is 8px
    • id - identifier for embedded media. Used to controll it
    • checkPolicyFile - connected to the security policy. Used with flash swf file embedded
  • <i> - text between those tags will be italic. 
  • <li>, <ul>, <ol> - lists. ordered and dotted
  • <p> - paragraph. Supports only two attributes:
    • align - specifies if text block is aligned to left/right/center or justify
    • class - connects with CSS class
  • <span> - inline part of text that allows only one attribute:
    • class - classname from CSS
  • <u> - text between those tags will be underlined

Saturday, August 6, 2011

Letter Spacing - TextFormat or css StyleSheet

If you;re looking for example of setting letter spacing - here it is.

The first solution is TextFormat. The property is named same in both options - letterSpacing. Let's see the code:

var txtfmodified:TextField = new TextField();
addChild(txtfmodified);
txtfmodified.y =20;
txtfmodified.text = 'hello world';
var tf:TextFormat = txtfmodified.getTextFormat();
tf.letterSpacing = 3; /* I tried lots of different values here. */
txtfmodified.setTextFormat(tf);

We can also use stylesheet to adjust part of text (in previous solution you can also adjust part of text but selecting chars is more complicated than using styles for classes of html tags). Here is the example:

var txtfmodified2:TextField = new TextField();
addChild(txtfmodified2);
txtfmodified2.y =40;
txtfmodified2.text = 'hello world';
var s:StyleSheet = new StyleSheet();
s.setStyle("p", {letterSpacing:3});
txtfmodified2.styleSheet = s;
txtfmodified2.htmlText = "<p>hello world</p>";

Remember that there are two solutions but you cannot mix them. Either way you'll receive error like this:
Error: Error #2009: This method cannot be used on a text field with a style sheet


And a proof at the end. First line is simple not modified field. Second line is modified by TextFormat properties. Third line is adjusted by stylesheet.