问题
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