This content has been marked as final. Show 9 replies
Follow-up: hmm, OK, looks like I might be able to get around this after correcting the XML file's encoding type... ;-P
However, I'm still curious if there's a solution to the original problem.
What happens if you don't escape the ampersand? Just thinking. I have no significant experience with character encoding.
That's exactly the problem -- except when including directly in the MXML, Flex seems to always "escape" the ampersand itself (as in, replaces it with ampersand-a-m-p-semicolon).
Just a thought but would '\&' make any difference?
I doubt it. That escape char works in AS, but I don't think it will in mxml.
Correct... I tried it (why not), and it doesn't work.
Anything else to try? I need a bullet in the label of a button created dynamically. Thanks.
Originally posted by: pjw-dpcp
The following works in MXML, producing a button labelled "Välkommmen" (note umlaut -- two dots -- over the 'a'):
<mx:Button id="test_button" label="Välkommen"/>
However, when trying to set the button's label dynamically via ActionScript like this:
var funkyLabel :String = "V&#228;lkommen hos oss";
test_button.label = funkyLabel;
...it HTML-entity-izes the ampersand, showing up as an ugly button label of "Välkommen hos oss".
WIthout knowing exactly how the MXML parser works, I'd say this makes perfect sense.
MXML is, really, XML. When the MXML compiler parses your XML, I imagine it dutifully converts any entities into their corresponding characters, just like any other XML parser.
The AS compiler, however, doesn't know anything about XML entities. So it just passes through the text value you've given. In order to get an umlaut, you'd need to use whatever facilities AS has for generating characters based on integer codes. Alternatively, there might be an entity decoder utility that would do this for you.
What I'm saying is that when the MXML is parsed by the MXML compiler (which is in part an XML parser, it's actually translating the entity to it's character code equivalent. So the button is turning into this:
<mx:Button id='test_button' label='Välkommmen' />
But there's no XML entity decoding when you do this in code.
That's my speculation, anyway.
I found a workaround for my problem, but it proably doesn't exactly solve anyone elses. I used a label, and its htmltext attribute. Then I coded rollover/rollout. Might not fit your needs though.