Skip to main content
Inspiring
October 10, 2009
Question

htmlText not working

  • October 10, 2009
  • 2 replies
  • 1063 views

My general problem is that I'm trying to change dynamic text (using button rollovers), but the buttons wipe out formatting that I apply in Flash properties, so I'm trying to use HTML styles instead. I'm using an AS2 file.

The strings I want to change are super short, so rather than create HTML files for each one, I'm wanting to change the strings in AS.

Bizarrely, however, I don't seem able to change the string in AS unless everything is loaded from an external file. Here is example code from the AS2 manual. And when I use the final line, it doesn't work.

this.createTextField("news_txt", 99, 50, 50, 450, 300);
news_txt.border = true;
news_txt.html = true;
news_txt.multiline = true;
news_txt.wordWrap = true;

var myVars_lv:LoadVars = new LoadVars();
var styles:TextField.StyleSheet = new TextField.StyleSheet();
var txt_url:String = "myText.htm";
var css_url:String = "html_styles.css";
styles.onLoad = function(success:Boolean):Void {
    if (success) {
        news_txt.styleSheet = styles;
     } else {
        trace("Unable to load CSS file.");
    }
};
styles.load(css_url);

myVars_lv.onData = function(src:String):Void {
   if (src != undefined) {
        news_txt.htmlText = src;
    } else {
        trace("Unable to load HTML file");
    }
};
//myVars_lv.load(txt_url);           // with just this line, it works fine
news_txt.htmlText = '<p class="headline">hello world</p>';          // adding this just results in unstyled text

What am I doing wrong? It seems like it must be something simple. A config problem? I'm using CS4.

Thanks,

Tim

This topic has been closed for replies.

2 replies

senortimAuthor
Inspiring
October 11, 2009

Ah, thanks. Right. I always forget that these things take time -- even when it's just on my local system.

kglad
Community Expert
Community Expert
October 11, 2009

you're welcome.

kglad
Community Expert
Community Expert
October 10, 2009

the stylesheet class has a load() method you should be using.  you should not be using the loadvars class.

senortimAuthor
Inspiring
October 10, 2009

I don't think that I am using the LoadVars class. That appears to be for the external HTML file (which I'm trying **not** to use.)

Shouldn't I just be able to change the innerHTML of the textfield object, without affecting its stylesheet connections?

The docs make it sound like I just need to set .html to true, and .multiline to true. The AS3 docs, while more precise, also seem a little ambiguous about what happens after you've set the data. My hope is to change the contents over and over again without having to reload the style sheet or create (potentially hundreds) of one line HTML files.

Thanks,

Tim

senortimAuthor
Inspiring
October 10, 2009

Well, nevermind. I switched the whole widget to AS3 and now it works.