Monday, March 23, 2009

Interchange Moved See you there.

Monday, November 05, 2007

Hash tabling with AS3

For some reason, there seems to be a bit of mystery surrounding hash tables and associative arrays in ActionScript 3. So I started digging into it a bit, because it seemed pretty simple. The culmination of my digging produced the following code which can be downloaded below.
Download File:

AS3 has an array class that easily handles associative arrays, and the syntax is simple:

var myArray:Array = new Array();
myArray["myKey"] = myValue;

It's that easy.
But now say you want to list the keys. Well, that's no problem, either. Not really:

for(var i:Object in myArray){
var keyList:Array = new Array();
and then you can move through the keyList array like you would any other array. Simple.
So we take these two simple pieces and shake them all up and produce something easy to use and relatively lightweight.

public dynamic class Hash extends Array{
protected var _keyArr:Array;
public function Hash(numElements:int=0){
this._keyArr = new Array();
public function addItem(key:String, value:Object):void{
this[key] = value;
public function getItem(key:String):Object{
return this[key];
public function get keys():Array{
return this._keyArr;
//this is done to avoid the warning when the keys are bound to something
public function set keys(a:Array):void{}
And there you have it. A simple Hash class that extends the built in Array functionality and adds in a couple of handy dandy features.

Tuesday, January 16, 2007

Flex 2 - IO Error #2032 - Web Service and Flex

So I was running into problems with this. Ran a quick google to find the solution - de nada. So I start deconstruction of my web service, of my Flex App, everything. Could be this, could be that. What was it? The file I was trying to write to was in use, by me (trying to update an XML that shows up in the Flex app). I've been using an HTTPService instead of a WebService to retrieve the XML. I guess now I'm going to move it into the WebService. There were no real solutions out there for this error, however, and I thought I'd let everyone know what I'd figured out.