ActionScript 3.0 Base64 encoder/decoder
Wednesday, 27 September 2006I’ve been working on a personal project recently (more on that later if/when it comes off) where I needed to be able to convert various bits of information into Base64 encoding and then back again. I couldn’t find a decent ActionScript 3.0 class, so I decided to roll my own.
The Base64 class can encode from or decode to simple strings or ByteArray objects, which means that you should be able to handle any type of data that can be written to or read from a ByteArray (which is pretty much everything).
I’ve tried to follow the conventions used in the ActionScript 3.0 libraries, including a FlexUnit tests/test runner in the download package, along with a script to build the test runner.
This class is working just fine for me, but I’m only exposed to a limited amount of Base64 data to test with. If you use this in your applications I’d be interested to hear your experiences. It’s released under the MIT license so is completely free for commercial use.
For more information see the Base64 class page, which is part of the revamped Goodies section.








Hi, I have implemented this "archiving" method in a RIA project
Paulius Uza | Wednesday, 27 September 2006 | 10:10 pmHi,
I have implemented this “archiving” method in a RIA project i’m currently working on.
I have a model where I have to store large amounts of data at the server, then read everything i have stored there. Here’s what i’m doing:
All I can say - It is really fast and it saves a lot of traffic. Thumbs up!
I had ported a Javascript implementation to AS 2.0 a
Jason Nussbaum | Thursday, 28 September 2006 | 2:56 pmI had ported a Javascript implementation to AS 2.0 a while back, and John over at undefined.com ported it over to AS 3.0.
http://blog.jasonnussbaum.com/?p=108 http://undefined.com/ia/2006/05/25/base64-encoding-for-actionscript-3flex-20/
Obviously, you don’t need it, but it’s there as an alternative…
Paulius: Good job - glad to hear it was useful. Jason:
Steve | Thursday, 28 September 2006 | 3:05 pmPaulius: Good job - glad to hear it was useful.
Jason: Yeah, I saw John’s version, but I needed one that could handle both String and ByteArray information. Still, as you say, its good to have alternatives.
Thanks Steve, your class saved me a lot of time
Webdevotion | Thursday, 25 January 2007 | 2:50 pmThanks Steve, your class saved me a lot of time when I ran into a problem sending a bytearray to my CFC. It would not accept it as binary.
Your class made it possible to send the string to my CFC and convert it to binary data using ToBinary. Problem solved ; )
Great work!
I'm running into some kind of problem that might come
Tamir | Thursday, 17 May 2007 | 8:50 amI’m running into some kind of problem that might come from the Base64 encoder : I’m encoding a JPEG ByteArray, and then I try to upload it to a Servlet (the upload is done using JavaScript).
I’m decoding it in Java using the apache-commons-codec package, and the resulting byte array is different from the source !!
Have you seen anything like that ?
Steve, i have been using your class ona project
Jacob Bullock | Tuesday, 31 July 2007 | 11:36 pmSteve, i have been using your class ona project where all data coming and going to the server is in byte arrays and we just stumbled onto a problem that we traced back to the class. It is believed that it has something to do with the + character as every fail case has a + in it and every success does not. I wish i had more info to give you, but the following string does not decode properly as far as I can tell: AAAAGQAAAAFGr7V+AAA4QAEyQUvPWZYpIl1fnYE1uzacIzliDl/z3SOaBL7+470r
going to investigate the issue more but thought you may be interested.
Jacob: Thanks for the bug report. I'll look into it
Steve | Wednesday, 01 August 2007 | 4:25 pmJacob: Thanks for the bug report. I’ll look into it and get back to you.
Just an update for those following the comment thread. Jacob's
Steve | Monday, 06 August 2007 | 1:44 pmJust an update for those following the comment thread. Jacob’s problem wasn’t caused by the Base64 class in the end, but by some weird URL encoding issue on his server.
Hi, good job but i'm a little confused if it could
Daniel | Tuesday, 14 August 2007 | 9:07 amHi, good job but i’m a little confused if it could work in flash professional 9.
Now i’m in a project which will implement a funtion: encoding and decoding xml files.
Pls give me some how to run it,thanks!
[...] good 2. search as3 base64 decode, still nothing 3.
Karenism » Archive » php v as3 | Sunday, 23 December 2007 | 11:07 pm[...] good 2. search as3 base64 decode, still nothing 3. search actionscript bas64 decode 4. found the perfect thing on dynamicflash blog 5. site wasn’t working properly; couldn’t download files 6. found [...]
[...] Base64 class from Andrew Webster, to convert the String
Drawing game for future world @ Goonhilly at tezzutezzu | Thursday, 27 March 2008 | 8:42 pm[...] Base64 class from Andrew Webster, to convert the String returned by the Adobe PNGEncoder class [...]
[...] ActionScript 3.0 Base64 encoder/decoder ???????? Base64???Steve Webster???Yahoo UK?Web Developer?Foundation
AS3, ??????????????(JPG,PNG) | ????tv?? | Wednesday, 08 October 2008 | 7:34 pm[...] ActionScript 3.0 Base64 encoder/decoder ???????? Base64???Steve Webster???Yahoo UK?Web Developer?Foundation ActionScript 3.0 with Flash CS3 and Flex??????? [...]
[...] di OrigamiStudio.it che ha utilizzato a sua volta un
Da SWF a immagine PNG con la classe ByteArray — Tutorials Flash CS3 Flash CS4 | Friday, 24 October 2008 | 4:46 pm[...] di OrigamiStudio.it che ha utilizzato a sua volta un codificatore da ByteArray a String creato da Steve Webster & dynamicflash.com ed implementando un PHP script è riuscito ad arrivare allo scopo. Grazie Daniele [...]
[...] [...]
ByteArray qustion - TOPCMM Community | Tuesday, 26 May 2009 | 12:50 pm[...] [...]