Tuesday, February 5, 2008

Colored <LI> Bullets in Flash

This blog entry will be from the geekery. If you are not interested in a problem explanation from the "realm of Geek-dom" then you might want to skip this one. Here goes!

As per my job, I spend a good chunk of time writing object oriented code in Flash for the purpose of creating eLearning. I work for a group called NXLevel Solutions (NXLevel Solutions)and most recently I have come across what appears to be a bug in Flash. Here is an explanation of the problem:

The problem (exactly):

  • When flash encounters any color treatment to text inside an <li> it applies the first occurrence of that color treatment to the bullet. The only case where this does not happen is when the first color treatment is the color #000000 (AKA "Black.")

  • So, when confronted with a stylized element with color treatment, Flash applies any color treatment other than black (#000000) to the bullet (i.e. a hyperlink color or a font tag applying some color.)

The issue here is that while you might want to highlight some text inside a Flash bullet using color, or possibly hyperlink to something and highlight the hyperlink (again, using color) you aren't likely to desire to have that one bullet (of a possible list of bullets) be in a different color. This is really irritating.

What is worse is that there isn't any good information on this topic out there on the web. Everyone on the web wants to know how to change the bullet color, usually to match the general text color, but there is nearly no blogging on the topic of stopping the bullet color from changing when the above condition is true. I eventually found one forum/blog on the topic:

http://geekglue.blogspot.com/2007/02/hacking-htmltext-in-flex-2.html

Search for Bullet, and the first occurrence on the page describes the problem in the flash player. Search again and the next occurrence explains a “hack!” that doesn’t work. Maybe this worked for someone in some situation (notice that this is really a Flex commentary)but it did not work for me. A variation of it did actually work, but this is completely a "hack" and not acceptable if you are working with dynamic content that contains bullets. Here is the "hack":

We have to trick Flash by applying a color treatment very (very) close to black, first, before anything else, on one or more characters, after the start of the "LI" tag . Examine the following:



When the above text is loaded into the htmlText property of a TextField in Flash, the second item would have an orange bullet. Now examine the following:



By applying the variant of Black (#010000) we get the bullet back, and the two black shades are virtually identical. This is a complete hack and for it to work, each and every HTML "LI" tag element would have to be examined and the first character of each "LI" would require replacement using this technique.

Two items of note before moving forward: This is not a problem if you compile your FLA into a SWF targeting Flash Player 7. Any target of Flash Player 8 or higher results in this problem and as far as I know, this is the only solution. here is an example of what the output specifically looks like once rendered:





Here we can see that while it solves the bullet color issue in Flash (in the second block of bullets) there are a number of other issues that then happen. For example, you have to implement the following content rules or you create more problems:

  1. No bulleted lists can start with a color treated element, like colorized text or colorized hyperlinks.
  2. All bulleted lists need to primarily contain black text (we cannot have the content of the bulleted list be “Blue” or anything other than black because the color of the text won't match the bullet or the first character of the Bullet text.)
  3. Someone would need to examine the copy for "LI" tags and search and replace each first character in each "LI" with the “hack” text, so flash can present it clearly.

This is horrible, but as of this moment, the only way I could figure it out. At the time I am writing this, the problem persists in the Flash 9 player (while the following downloadable example it written using Flash Pro 8) i can tell you that rendering the SWF in Flash CS3 targeting for any Flash Player other than version 7 still remains problematic!)

Here is the downloadable example:

http://enginpost.com/pics/blog/flashbullets/bulletTest.fla

Adobe (if you are listening)... is there a better solution to this? If not, could we get a priority patch to players 8 and 9 (and 10?), and get an update to the Flash Pro 8/CS3/(CS4?) authoring environment? While I am certain you could fix this for FP 10, please, remember that many of us still HAVE TO TARGET older players, because our client networks are not implementing the latest flash player versions.

Thanks and if anyone has a solution, feel free to comment.

UPDATE:

If you are also having problems with nested bullets and thought they were not possible in flash, read this blogpost to solve your HTML nested bullets in Flash issue.

15 comments:

Snaerd said...

Thanks a million, mister! Solved a bug the client was nagging about real hard!

Anonymous said...

thanks a lot... i was really confused about this

Anonymous said...

Alternatively, you could replace the bullet tag with an image which looks like a bullet. That might work

Anonymous said...

I wanted to add quickly, though you will be able to read my documentation in the near future on my blog flashplaya[dot]net why this occurrence is actually happening.

In AS2 when you use html text and then use the += to concat extra text to the current text, what happens behind the scenes is it stores locally the .text vs the htmlText and then stores locally the htmlText tags used.. Then the += actually adds to the locally stored regular text and then adds that to the htmlText and then rea-applies the quasi proper tags.

That is why the text fields breaks what appears to be something in code to work. During the addition of new text, some of the tags are stripped and never re-inserted.

I have created a special htmlTextBox that will be on my blog soon, that will allow those who use a lot of htmlText to really take advantage of the way htmlText should have dealt with things.

-iBen

Anonymous said...

Just wanna say thanks mate! This was a really annoying bug and your fix worked great!

Sonic said...

This bug still appear in CS3... great thanks for this post.

Danny said...

Was looking for a fix like this today, but your solution came too late. We had to just remove the bullets instead.

To answer @Anonymous, we wanted to just use an image in place of the bullet, but unfortunately then the text doesn't wrap right if the bullet is more than one line.

Monte said...

Thanks a zillion!

nephiw said...

This bug had been frustrating me for a long time, none of the solutions listed here were successful for me as I am displaying text read from an xml, and colored via CSS in a text area.

However, I did finally find a solution using Regular Expressions, the bullet symbol, and the block indent. I sent the source code to Steve of this block and I hope he will post it for everyone.

Anonymous said...

THis is what i am exactly looking for....but i am unable to see the workaround ....its redirecting to a page where it is deleted....It would really help me if u can post it again

Deccan Chargers said...

I cant see ur solution for this issue...guess it was removed...can you please post it again...Thanks in advance

Unknown said...

Hey guys... just ran into the same problem. I ended up color transforming my dynamic text field while still using the < ul >< li > markup in my xml. For what I needed it seemed to work pretty well.


myColor = new Color(p_txt);
myColorTransform = new Object();
myColorTransform = {rb:255, gb:255, bb:255};
myColor.setTransform(myColorTransform);

Jonathan Bergeron said...

Thank you so much !!!

Unknown said...

Thanks for this post! Happened to get a problem report regarding this for an application ported from Flash 7 compiled code to AS3 and Flash 9. Go figure, this thing works properly in Flash 7.

Want to leave off my solution to the 3 formatting issues you listed this fix causes. If you do this when assigning the html text:

field.htmlText = txt.split("<li>").join("<li><font color=\"#010000\" size=\"2\"> </font>")

Then your fix works as expected and doesn't cause other formatting issues. You'd probably have to do this 3 more times for <Li>, <lI>, and <LI> tags to be truly dynamic.

Unknown said...

Sorry, my fix won't work because then flash also applies size=2 to the bullet. I was just too happy to not see a blue bullet and didn't notice there was no bullet at all! I was trying to use a space character as an invisible character and size it down to not have a noticeable effect, but utf-8 actually has a 0-size space character, so here's a better fix.

field.htmlText = txt.split("<li>").join("<li><font color=\"#010000\">\uFEFF</font>");