Skip navigation
Currently Being Moderated

<b> and <i> tags not working in StyleableTextField for mobile development

May 14, 2012 9:14 AM

Tags: #flex #html #mobile #actionscript #flex_mobile #4.6 #flex_4.6 #styleabletextfield

I'm trying to dynamically produce TextArea instances in a Flex mobile app that implement html formatting.  I've made a lot of progress, but simple <b> and <i> tags are not being rendered correctly. 

My current hypothesis is that I need to embed the italic and bold fonts.  I am currently not embedding fonts for these particular TextArea instances at all -- they are rendering using the system font.  In my previous experience, this eliminates problems with rendering <b> and <i> text.  However, when deploying on mobile platforms, I don't know for sure if there is a bold or italic system font natively available. 

 

If I need to embed the bold and italic fonts for the tags to process correctly, does anyone know which font(s) I should embed and how I should name them so that the html will be able to find them and render correctly?  I am applying a CSS to these TextArea instances in the full app, so I can do any font embedding there if necessary.  I am planning to compile this app for both iOS and Android, in case that makes a difference. 

 

Below is a simplified example of the code I'm using.  The TextArea that is generated is formatted honoring the <br /> tags, but ignoring the <b> and <i> tags. 

 

Thanks in advance for any help. 

 

import mx.events.FlexEvent;

import spark.components.TextArea;

import spark.components.supportClasses.StyleableTextField;

import spark.skins.mobile.TextAreaSkin;

 

protected function application1_creationCompleteHandler(event:FlexEvent):void

{

          var textArea0:TextArea = new TextArea();

          textArea0.setStyle("skinClass", TextAreaSkin);

          addElement(textArea0);

          var styleableTextField0:StyleableTextField = StyleableTextField(textArea0.textDisplay);

          styleableTextField0.multiline = true;

          styleableTextField0.htmlText = "<b>bold</b><br /><i>italic</i><br />normal";

}

 
Replies
  • Currently Being Moderated
    May 14, 2012 1:35 PM   in reply to sabird

    Try it in a non-mobile app to make sure you’ve got the right code.

     
    |
    Mark as:
  • Currently Being Moderated
    May 18, 2012 2:21 PM   in reply to sabird

    I think you can swap in a mobile skin on a desktop app.  Does it work in a mobile app run on the desktop emulator?

     

    If you are not embedding any fonts, then it shouldn’t matter that you embed bold and italic versions, but if you are, then you have to embed for all bold/italic combinations.

     

    Also, the styleSheet property on a TextField is not the same things as the Flex CSS style subsystem.

     
    |
    Mark as:
  • Currently Being Moderated
    May 18, 2012 11:30 PM   in reply to sabird

    You would have to add the mobile swcs to your project to use them on the desktop.

     

    In the emulator try to get to the properties on the StyleableTextField.  Is embedFonts = true?  What is the htmlText property value?

     
    |
    Mark as:
  • Currently Being Moderated
    May 20, 2012 10:45 PM   in reply to sabird

    It is possible that there  is some behavior in the text components that read the text property from the TextField and re-write it which would blow away any html you have applied.

     

    In general, Flex has not supported folks going after the low-level TextField and/or using the TextField’s styleSheet property.  You are supposed to use the Flex CSS instead.

     

    A next test might be to subclass StyleableTextField so you can wrap the text and htmlText getter and setters so you can see who is reading/writing those properties.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points