How to “append” html text to text area in flex and flex mobile project to display sprite and text formatting

元气小坏坏 提交于 2019-12-08 07:06:24

问题


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]


回答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




回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/6260417/how-to-append-html-text-to-text-area-in-flex-and-flex-mobile-project-to-displa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!