Superfast Base64 Actionscript Library

So I was using this Base64 Actionscript class for Base64 encoding/decoding a byte array while working on my cofounded project 15Seconds.me. The Base64 class is by Jean-Philippe Auclair, and according to his own benchmarks, runs about 700% faster than Adobe’s own Base64. He has a nice explanation of how he made some improvements, and considering it was high up on Google’s search results for Base64, I started using it.

That is until I came across another Base64 Actionscript library over at Valentin Simonov’s blog.

BlooDHounD’s Crypt class turns out to be even faster than Jean’s class – about 17 times faster. The code for BlooDHounD’s class is unavailable (only a SWC is given). I imagine the library was written in C/C++ and exported to a SWC using Adobe Alchemy considering the speed improvements (alchemy applications can run way faster than AS3 native code).

JavaScript Function declaration cautions!

Just found Kontagent‘s JavaScript library has a issue. When you declare functions in JavaScript as so below, the behavior isn’t as expected!

a = 5;

if (a == 5)
{
    function yo()
    {
        alert("good");
    }
}
else if (a == 6)
{
    function yo()
    {
        alert("bad");
    }
}

yo();

Be sure to declare your dynamic functions like so:

a = 5;
var yo;
if (a == 5)
{
    yo = function()
    {
        alert("good");
    }
}
else if (a == 6)
{
    yo = function()
    {
        alert("bad");
    }
}
yo();

As in Actionscript (also ECMAScript based), declaring functions the first way will be global scope. And the last function defined will be the one that is used.

We were trying to debug why Kontagent‘s library wasn’t pinging the right events (in our case Invite Sent notifications). When we investigated the code we saw they wrapped function calls inside ifs as above… Hopefully they will read this blog post and implement a fix as suggested :-).
So be careful developers!

*Edit: We sent a Pull request to their github with our fix