AS3 Encoder/Decoder for Special Characters
January 7th, 2011 by
Adrian Parr
Here is a little tool that I have made which can be used to encode and decode strings into URL escape sequences (eg. convert special characters so they are safe to transmit in a query string). I recently also had the need to encode and decode HTML named entity references (eg. ” becomes ”) and after a long hunt around the web I couldn’t find one in AS3. So I have also written a static class called HTMLEntities which has the public methods ‘encode’ and ‘decode’. Hopefully you will find it useful. All the source code is available below.
Download a ZIP of the source code here
NOTE: If you use the HTMLEntities class, you may want to remove the entry for the apostrophe (‘) which encodes it as ' because it is not supported by Internet Explorer. Apostrophes are better off being encoded as '
Here are some useful lists of the HTML Named Entities …
- w3schools – HTML ISO-8859-1 Reference
- w3schools – HTML Symbol Entities Reference
- Wikipedia – List of XML and HTML character entity references
- FileFormat – HTML Entity Names
- Webmonkey – Special Characters
And these are handy conversion tools …
Posted in ActionScript 3.0, Sample Code |
5 Comments »
March 24th, 2011 at 4:24 am
Very nice. Keep getting a message that your zip file is corrupted when I try to open it.
April 14th, 2011 at 2:08 am
This is great! Just what I was looking for!
May 5th, 2011 at 11:11 am
@Mark: Sorry about that. The ZIP file must have got corrupted when I uploaded it. I have re-uploaded it again now.
http://www.adrianparr.com/flash/encoderDecoder/encoderDecoder.zip
October 21st, 2011 at 12:14 pm
Under which license is the source code published?
October 21st, 2011 at 3:08 pm
@Tony: Feel free to use it for whatever you want. I don’t mind. I’m not sure if that is GPL or MIT license. If you want to use it for a commercial project, then that is fine with me. Glad it was useful to you.