Dynamic Flash

Confessions of a serial code abuser
  • rss
  • Home
  • MTASC
  • Archives
  • About me
  • Goodies
    • Base64 encoder/decoder class
  • My Bookshelf
  • My Talks

Base64 encoder/decoder class

Introduction

The Base64 class can encode String or ByteArray objects to Base64 encoding, and vice versa.

Note that this class is ActionScript 3.0 only as there are several good alternatives written for ActionScript 2.0. Just google them.

Download

The current version of the Base64 class is 1.0.0.

Download Base64 1.0.0

Usage

Encoding from and decoding to string:

PLAIN TEXT
Actionscript:
  1. import com.dynamicflash.util.Base64;
  2.  
  3. var source:String = "Hello, world";
  4. var encoded:String = Base64.encode(source);
  5. trace(encoded);
  6.  
  7. var decoded:String = Base64.decode(encoded);
  8. trace(decoded);

Encoding from and decoding to ByteArray:

PLAIN TEXT
Actionscript:
  1. import com.dynamicflash.util.Base64;
  2.  
  3. var obj:Object= {name:"Dynamic Flash",url:"http://dynamicflash.com"};
  4. var source:ByteArray = new ByteArray();
  5. source.writeObject(obj);
  6.  
  7. var encoded:String = Base64.encodeByteArray(source);
  8. trace(encoded);
  9.  
  10. var decoded:ByteArray = Base64.decodeToByteArray(encoded);
  11. obj = decoded.readObject();
  12. trace(obj.name + "(" + obj.url + ")");

History

1.0.0
Initial release

Bug reports

Please post bug reports as comments to this page.

License

The Base64 class is released under the MIT license.

Copyright © 2006 Steve Webster

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments rss
Comments rss
Trackback
Trackback

14 responses

[...] For more information see the Base64 class page, which

ActionScript 3.0 Base64 encoder/decoder at Dynamic Flash | Wednesday, 27 September 2006 | 8:51 pm

[...] For more information see the Base64 class page, which is part of the revamped Goodies section. [...]

[...] Base64 encoder/decoder class at Dynamic Flash (tags: Base64 as3)

danielyuen.hk Blog : links for 2006-09-29 | Friday, 29 September 2006 | 12:50 am

[...] Base64 encoder/decoder class at Dynamic Flash (tags: Base64 as3) [...]

Dude, you rock. This works great, and was exactly

Chris | Friday, 10 November 2006 | 1:07 am

Dude, you rock. This works great, and was exactly what I was looking for! In particular, the ability to encode a byte array.

[...] http://www.dynamicflash.com/goodies/base64 [...]

Actionscript Classes » Base64 | Saturday, 16 December 2006 | 5:08 am

[...] http://www.dynamicflash.com/goodies/base64 [...]

[...] Steve Webster’s Base64 class and just use the result

Iconara » Flex WebServices, problem with <any/> | Tuesday, 25 September 2007 | 8:05 am

[...] Steve Webster’s Base64 class and just use the result of Base64.encode(document.toXMLString()) as a parameter to the web service. [...]

[...] Base64 De- and Encoder in Actionscript [...]

Tinkerlog » Blog Archive » Webcam snapshots with Flex3 | Saturday, 03 November 2007 | 6:34 pm

[...] Base64 De- and Encoder in Actionscript [...]

Great stuff. If copying and pasting the examples above to

Emma Jones | Tuesday, 11 March 2008 | 12:24 am

Great stuff. If copying and pasting the examples above to test them - just watch the typo in line 1 of the first example about encoding and decoding from String; should be util not utils

Emma: Thanks for letting me know about the typo. I've

Steve | Wednesday, 12 March 2008 | 3:13 pm

Emma: Thanks for letting me know about the typo. I’ve just updated the code example :)

excellent stuff! This does exactly what i needed! Kudo's for you!

erik | Monday, 31 March 2008 | 6:34 pm

excellent stuff! This does exactly what i needed!
Kudo’s for you!

very useful.. thanks!

backz | Tuesday, 13 May 2008 | 4:18 pm

very useful..
thanks!

I was kind of hoping there'd be one in as3corelib;

Karel | Thursday, 15 May 2008 | 7:09 am

I was kind of hoping there’d be one in as3corelib; but there isn’t.
Thank you for sharing this

[...] is only available to Flex. Luckily with the richness

import mx.utils.Base64Decoder in Flash CS3 | import Slice.of.Infinity; | Wednesday, 16 July 2008 | 7:06 am

[...] is only available to Flex. Luckily with the richness of the web, I found an alternative dynamicflash’s Base 64 Class . However, i still think it’s possible to use Flex library into Flash (AS3) and i found out [...]

[...] http://dynamicflash.com/goodies/base64/ « b+樹數據結構 [...]

岛屿 » Blog Archive » Base64 encoder/decoder class | Sunday, 20 July 2008 | 7:43 am

[...] http://dynamicflash.com/goodies/base64/ « b+樹數據結構 [...]

thanx.

sses | Monday, 28 July 2008 | 11:18 pm

thanx.

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

About Dynamic Flash

Steve Webster is a Senior Web Developer for Yahoo! in London, UK.

He is more than a little concerned that he defines himself in terms of his career, and that he talks about himself in the third person.

Find out more

Recent Posts

  • Read and write local files with Flash Player 10
  • The problem with SproutCore
  • Yahoo! London seeks Junior Developers
  • I am Singularity
  • Yahoo! Astra component library 1.1 released

Tags

Accessibility ActionScript actionscript3 actionscript 3.0 air apple astro book conference designer filereference file upload Flash flex framework internet internet explorer JavaScript jobs junior microsoft opportunities ria singularity08 skin tutorial urlrequest web developer web development Web Standards Yahoo!

del.icio.us-ed

Stuff

Singularity?
Flex.org - The Directory for Flex
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox