Em-Dash in Flash HTML Text

It’s been a LONG time since my last post, and that is mostly because I haven’t been doing much Flash development recently. As Apple shuts out Flash, I’ve been forced to throw in the towel and say, “if you can’t beat em, join em”. Yep, so I’ve been building iPhone apps.

Anyway, fortune has thrown some Flash work my again, and it’s been great fun getting back into. However, here in the debugging phase I’m coming back to some of the weird old quirks of Flash content that I always had to keep a cheat-sheet handy for. One of those points being: how the heck do you put em-dash characters into Flash HTML text?! It seems so simple… after embedding the em-dash font character, you should just be able to put the character into UTF8 text, right? Or at the very least, you should be able to use the — entity, right? Wrong. You have to use the ASCII entity. Okay, that’s simple enough; except that when I look up the em-dash ASCII code most conversion tables list —–which does NOT work. Gar! So, I’m not sure why em-dash has multiple ASCII values, but the one that works in Flash is —. Please post in comments if you can elaborate on the difference between those two ASCII codes, I’d be curious to know the difference!

And for those just skimming the article, here’s the bottom line… to make an em-dash in Flash HTML text, just embed the font character and then use this ASCII code in your text: —

Advertisements

5 comments so far

  1. Jalen Wanderer on

    Please post in comments if you can elaborate on the difference between those two ASCII codes, I’d be curious to know the difference!

    The difference is that only one of those is actually an ASCII code. And even that one is only sort of an ASCII code.

    ASCII codes, technically, only go from 0 to 127. However, the range of 128 to 255 is known as “extended ASCII”, and in practice is often lumped in with regular ASCII. 151 is the extended ASCII code for the em dash.

    With only 256 characters, though (fewer than that, actually, since some of the numbers are taken up by control codes), even the extended ASCII code doesn’t have room for a lot of symbols or special characters. There’s another standard, Unicode, that goes far beyond that range, and includes many different symbols and alphabets. Any time you use a character code with a number greater than 255, you’re not using ASCII; you’re using Unicode.

    For the first 128 characters — the standard ASCII characters — Unicode and ASCII match up. They also do for most of the extended ASCII range. However, the positions from 128 to 159 on the Unicode charts, which include various characters in extended ASCII, instead are control codes in Unicode. These characters certainly exist in the Unicode standard; they just have different code numbers. 151, which is the em dash in ASCII, in Unicode is a control code meaning “end of guarded area”. In the Unicode standard, the em dash is at number 8212.

    So I guess the bottom line is that apparently Flash uses Unicode instead of ASCII.

    (You can see the complete Unicode charts here… seriously, there are a lot of characters there. Of course, not all of them will actually be usable on a given computer — many of them may require special fonts to be installed.)

  2. Jalen Wanderer on

    I should add: Unlike the basic 128-character ASCII code, the extended ASCII code isn’t really standardized. The version that has the em dash at 151, the Windows-1252 encoding, is only one variation; it happens to be the standard used by English versions Microsoft Windows, as well as those in certain other European languages, but it’s by no means universal. So in a way, it makes sense that Flash would use Unicode instead of a particular Windows version of extended ASCII, since it’s not intended just for use with Windows.

  3. Brian Wong on

    A ps to anyone struggling with this issue.

    If you’re reading in an external text file you can use:

    %26%238212%3B

    – To get past the loader;

    var myTextLoader:URLLoader = new URLLoader();
    myTextLoader.dataFormat=URLLoaderDataFormat.VARIABLES;

    which will then get read in as — -before- being converted to HTML text, allowing an mdash to appear on screen


    myVariable = String(e.target.data.myTextFileVariableName);
    (TextField)this.myTextFieldName.htmlText = myVariable;

  4. yohollo on

    Hi Greg,

    stumbled upon your blog through another post so I thought I could maybe give some of the enlightment that one brought to me back.

    The difference between the 3-digits char code and the 4-digits one is the referenced charset. The 4-digits is the UTF-8 one and since everything in Flash is UTF-8 it can only make use of these ones. I guess you already figured that out so I hope I do not come off as Mr. Smarty-Pants. One thing remains strange though: It leaves me surprised that the character does not get displayed when simply entered in the text non-entitied [is that a word?]. I have to check that for myself :) I would have suspected an encoding issue in the input text or file you may be parsing.

    Nevertheless, have a nice weekend!

  5. Kerrin on

    Standard ASCII Characters only go up to 127
    There is extended ASCII that goes up to 255
    UTF-8 is compatible with Standard ASCII (the first 127), but does not support extended ASCII, because of the way it works to get dynamic multi-byte characters.
    The character you are attempting to get is in the extended ASCII character set, so in UTF-8 it is in a different place.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: