Question

IN A NUTSHELL
I have a flash application (made for flash lite - actionscript 2). When I load in my application an XML File and I process it in an object. I get the correct html input in a textfield.
However if I hardcode the object, all html tags disappear from the .htmlText attribute and there is code placed in front of the text. It is my intention to hardcode the object, since the loading goes a lot fast then xml.

long story short: string.html = true; deletes all span tags, while I need those. How do I get the span tags in the htmlText of my textfield?

MORE INFO BELOW

In my application I create textfields put some text in them and then set the correct x and y value so they are all nicely put beneath eachother.

inside the function:

//ABOVE I CREATE TEXTFIELD USING THE .CREATETEXTFIELD FUNCTION
this["text" + this._textFieldCounter].html = true;
this["text" + this._textFieldCounter].multiline = true;
this["text" + this._textFieldCounter].wordWrap = true;
this["text" + this._textFieldCounter].autoSize = true;
this["text" + this._textFieldCounter].styleSheet = this._styleSheet;
this["text" + this._textFieldCounter].condenseWhite = true;
this["text" + this._textFieldCounter].htmlText = "<span class=\"page\">" + strHtmlText + "</span>";
//trace(this["text" + this._textFieldCounter].htmlText);

When I trace the htmlText I get

<P ALIGN="LEFT">
<FONT FACE="Times New Roman" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0">
//here comes the strHtmlText
</FONT>
</P>

Flash automatically put those p and font tag in front of my text. So my stylesheet won't show the correct style. How do i get rid of the initial align and font tag but still keep the textfield as html?

EDIT
By setting a textformat I have found a way around this problem... HOWEVER
I have a new problem:
In my strHtmlText there are span-tags ( <span class="text-in">blabla</span> ), but this gets filtered out. Why's that ? my stylesheet doesn't do anything without those styles.

(text is loaded from an array)

Was it helpful?

Solution

It must have something to do with the order in which you assign the properties to the TextField. It should be: 1. set field.html to true, 2. assign styleSheet, 3. set htmlText. The styleSheet must be set before the htmlText is assigned - I originally posted a link to the as3 documentation, but this is true for both AS2 and AS3.

Try this: Put a TextField on the stage of a new AS2 FLA. Set its type to dynamic. Name it to "_textField". Set the font to Verdana, 16px, Black. Enter "Error." or something similar into the TextField, so that it has some text in it. Click "Embed fonts", be sure to include a sufficient amount of letters, like ascii or Latin-1. On the timeline, enter this code into the first frame of the Movie.

var style:TextField.StyleSheet = new TextField.StyleSheet();
style.parseCSS("p {font-family:Verdana; font-size:12px; color:#FF0000;}");
_textField.html = true;
_textField.styleSheet = style
_textField.htmlText = "<p>This is a test.</p>";
trace (" new text:"+_textField.htmlText);

Now when you run the program, it should change the text to "This is a test", the color to red and the font size to 12 px. It does on my computer. Also, the trace prints the exact same text that is assigned to htmlText.

Now go back and exchange the lines assigning the styleSheet and htmlText properties. Re-run the program. It will have all the extra tags you were complaining about.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top