AS3 Encoder/Decoder for Special Characters

January 7th, 2011 by Adrian

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 …

And these are handy conversion tools …

Posted in ActionScript 3.0, Sample Code | 5 Comments »

5 Responses

  1. Mark Says:

    Very nice. Keep getting a message that your zip file is corrupted when I try to open it.

  2. Kawika Says:

    This is great! Just what I was looking for!

  3. Adrian Parr Says:

    @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

  4. Tony Says:

    Under which license is the source code published?

  5. Adrian Parr Says:

    @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.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.