Saturday, September 13, 2008

a random utility class: ObjectSerializer.

I'm just going through and editing a few old posts. This package (objectSerializer) was one that was needed in the case of a serialized object needing to be passed through a url (yes, we had a case where that was needed).

package of.lovin
{
import flash.utils.ByteArray;

import mx.utils.Base64Decoder;
import mx.utils.Base64Encoder;

public class ObjectSerializer
{

public static function decode(str:String):*
{
// '+' equals '-' and '/' equals '_'

if (str != null)
{

var myPattern : RegExp = new RegExp("-", "g");
var myPattern2 : RegExp = new RegExp("_", "g");
var myPattern3 : RegExp = new RegExp("~", "g");

var urlModifiedString : String = str;
urlModifiedString = urlModifiedString.replace(myPattern,"=");
urlModifiedString = urlModifiedString.replace(myPattern2,"/");
urlModifiedString = urlModifiedString.replace(myPattern3,"\n");


var bytes:ByteArray = new ByteArray();
var bDecoder : Base64Decoder = new Base64Decoder();
bDecoder.decode(urlModifiedString);
bytes = bDecoder.toByteArray() ;

bytes.position = 0;

return bytes.readObject();
}
return null;

}

public static function encode(obj:*):String
{
// '+' equals '-' and '/' equals '_'

var bytes:ByteArray = new ByteArray();
bytes.writeObject( obj );

var bEncoder : Base64Encoder = new Base64Encoder();
bEncoder.encodeBytes(bytes);

var myPattern : RegExp = new RegExp("=", "g");
var myPattern2 : RegExp = new RegExp("/", "g");
var myPattern3 : RegExp = new RegExp('\n', "g");

var urlModifiedString : String = bEncoder.toString();
urlModifiedString = urlModifiedString.replace(myPattern,"-");
urlModifiedString = urlModifiedString.replace(myPattern2,"_");
urlModifiedString = urlModifiedString.replace(myPattern3,"~");

return urlModifiedString ;
}

}
}

Saturday, May 10, 2008

Flex Builder / Eclipse tip du jour.

It's inevitable. You'll be debugging a Flex application, get an error and will need to look at a class, object, function or the like. Instead of scrolling up and down, or digging through directories, do the following:

Ctrl-click on the 'identifier' in question and you're in like Flynn.

30th time is the charm?

Maybe it's a bad idea to start ANOTHER blog that may fall into the same ol' my-last-post-was-five-months-ago pit. But, what the hell...