0

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)

Jozzeh
  • 841
  • 10
  • 28

1 Answers1

1

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.

weltraumpirat
  • 22,544
  • 5
  • 40
  • 54
  • I'm working with AS2 (as defined in the tags)... however if I set the stylesheet-property before the htmlText, it is still the same issue. – Jozzeh Dec 20 '10 at 07:54
  • I edited the original post and provided an example instead. I still think there is something wrong with the order in which you assign styleSheet and htmlText. Or perhaps the styleSheet isn't properly initialized. This is not a bug in Flash, however. – weltraumpirat Dec 20 '10 at 09:23
  • I agree that your arguments and example work. However when I try it in my application, the span tags still get removed from the string if the html parameter is set to true. I would even say that all normal html such as bold and italic tags get removed as well. Only the flash font-tag remains and double br-tags become a closed paragraph tag. – Jozzeh Dec 22 '10 at 13:44
  • Well, I have been using spans for quite a while - there is absolutely no reason they shouldn't work. Except if there is something else not quite right in your program. I would advise looking at fonts and stylesheet initialization: If Flash can't find the proper fonts and/or styling information, almost always nothing is displayed. – weltraumpirat Dec 22 '10 at 16:19
  • 1
    Hi, it's me again: What you are describing is exactly what happens, when the StyleSheet is not available, or if the styles in your htmlText are not in it, or if the fonts used in those styles are not embedded. Can you please check if your styleSheet is loaded and initialized correctly by the time you call textField.htmlText? Maybe just hardcode the styleSheet like I did, to make sure the styles are available. Also, check if the font names in your StyleSheet are equivalent to the font screen names in flash. Use Font.enumerateFonts() to check. – weltraumpirat Dec 22 '10 at 18:51
  • Thank you so much! The stylesheet was 'undefined'. Still strange that the stylesheet was defined when the text was loaded from an xml... but the end result counts. You solved my problem (even though you had to explain it several times ;-) ). – Jozzeh Dec 23 '10 at 07:36
  • For future generations, why was my stylesheet not loaded: I initialised an instance of a movieclip ( new movieclip ), then i put the stylesheet on that empty movieclip and after that i loaded in an existing movieclip using attachmovie in my new movieclip -> loss of stylesheet. Using XML maybe there was some delay... I can only guess. – Jozzeh Dec 23 '10 at 08:14