1

I'm playing around with a messaging type of application. Does anyone know how, or of any tutorials on to "appending" html text to text areas in flex and flex mobile projects? And specifically how I could take that and basically "append" a sprite inline to the text when i need to? Something simple like:

Username: some text right here!

So, Anyone have any experience "appending" sprites or simple text formatting? Thanks I'm realy stumped on how to solve these issues!

EDIT: Based on an answer below it was sugguested that it's as simple as...

textAreaInstance.htmlText += "<b>Username:</b> some text right here!";

But its not. you can't do .htmltext with a text area. you can on a text field, so i tried

var TF:TextField = new TextField();
TF.width = 200;
TF.height = 200;
TF.htmlText="Image in textfield: <img src='http://upload.pusha.se/3/HittaTidning_75.jpg' hspace='0' vspace='0'>";

//then i go to my text area instance and tried to add it the way you suggested                  
text_area_instance.text += TF;

All this displays is [object TextField]

brybam
  • 5,009
  • 12
  • 51
  • 93

3 Answers3

1

There is no method to append html text, so you have to use += appending your html formatted stuff:

    textAreaInstance.htmlText += "<b>Username:</b> some text right here!";

You can embed display objects in TextArea in this way:

    <fx:Script>
    <![CDATA[
        //display object class, what simply draws a recangle
        //you have to create a reference from this class, otherwise it won't work
        private var img:ImageStuff;


        protected function button1_clickHandler(event:MouseEvent):void
        {
            txt.htmlText = "<img src='ImageStuff' width='16' height='16'/>";
        }

    ]]>
</fx:Script>

    <mx:TextArea id="txt"/>
    <s:Button click="button1_clickHandler(event)" />

I don't know any way embedding display objects into spark TextArea.

Cheers

Tamas Gronas
  • 573
  • 3
  • 8
  • I was playing around with the first part of your answer. I dont think it's as simple as your putting it. Because first of all you cant do .html text like that with a text area. It needs to be a text field, look at my edit i'll show you what i tried based on your answer, but it just displays [object text field] – brybam Jun 07 '11 at 13:49
  • Maybe I wasn't clear enough, so the TextArea in the mx package has htmlText property, thats why I used this in my example, because I could create a proper workaround with this component. – Tamas Gronas Jun 07 '11 at 16:13
  • If you want to use s:TextArea, see it's textFlow property, and the TextFlowUtil class, but but you can't embed display objects to this component with . – Tamas Gronas Jun 07 '11 at 16:19
0

For mobile this works (Worked for me):

Check this link http://remotesynthesis.com/post.cfm/adding-html-text-to-a-flex-mobile-textarea

but use StyleableTextField instead of MobileTextField

racharambola
  • 417
  • 1
  • 8
  • 26
-1

All you need is htmlText property of TextField:

tf.htmlText = "<b>Username:</b> some text right here!"

look here for details.

As for embing sprite. Similar question was asked before. take a look at Actionscript problem in Dynamic TextField

Community
  • 1
  • 1
Eugeny89
  • 3,797
  • 7
  • 51
  • 98