Tuesday, November 16, 2004

problems displaying html in a Flash TextField

I had a bunch of scrolling content that I needed to put in a bunch of pages. Rather than wrestle with trying to make a nice-looking scroll area for all browsers in HTML, I decided to use Flash instead.

Getting flash to load in a bunch of raw text and display it as HTML was not hard.

Here's the ActionScript that works for this:

// "output" is a Dynamic text field that I already created.
// there is no variable name for this field, output is the instance name

output.html=true;
output.multiline=true;
output.wordWrap=true;
output.selectable=true;
output.condenseWhite=true; // I like to have readable HTML
output.mouseWheelEnabled=true; // makes it nice for scroll wheels

loadedText = new LoadVars();

// I like onData versus onLoad, that way I can have just HTML in a plain text file
loadedText.onData = function(raw) {
output.htmlText=raw;
}

// "outputSource" is a variable passed in via
// the object and embed tags containing the
// name of the text file to be loaded
loadedText.load(outputSource);


My problems started when some of the characters went awry, then my image wouldn't show up.

I'll address the image problem first. If you are trying to publish out for Flash Player 6 or earlier, don't even try to read in "img" tags, they won't work. But I was having problems in 7.0 player as well, and it about drove me crazy figuring out why.

If the "img" tag is near the end of the html you are going to display, it can get chopped off. No image will display. If you don't have the condenseWhite property set to true, you can put a bunch of carriage returns then some throwaway character (like a period) at the end in your text file. I like to have clean HTML, though, so I leave condenseWhite set to true, then use "br" and "p" tags to set my carriage returns in the output. So I didn't put the image at the end (you could probably doctor the image so there's a margin that matches the background of the page)

As far as the characters not displaying correctly, you can
go here for a reference. I was having problems with ndash and apostrophe. "[ampersand]apos;" was just showing a single quote ('), so I used [ampersand]#8217;, which showed up correctly (’). For ndash, I used the standard [ampersand]#8211; ( – )

1 Comments:

Anonymous Anonymous said...

try using gchats textbox component

http://www.gchats.com/proceed.asp?item=16

ability to adding smiles images and icons between htmltexts

1:18 AM  

Post a Comment

<< Home