         } else if ((code & 0x04) == 0) {
             // it's a new trait, read class name & N sealed variable names
             var alias :String = decodeString();
-            var className = (alias.length > 0) ? AMF3.getClassNameByAlias(alias) : "";
+            var className = (alias.length > 0) ? AMF3.getClassNameByAlias(alias) : null;
             var N :uint = code >> 4;
             var vars :Array = new Array(N);
             for (var ii :int = 0; ii < N; ii ++) {
                 vars[ii] = decodeString();
             }
             traits = new Traits(className, (code & 0x08) != 0, vars);
-            _ctx.tRef.table[traits] = _ctx.tRef.ix ++;
+            _ctx.tRef.push(traits);
 
         } else {
             throw new Error("IExternalizable serialization not supported");

{
    public var bytes :ByteArray;

    public var oRef :References = new References();
    public var sRef :References = new References();
    public var tRef :References = new References();

    public function Context (bytes :ByteArray)
    {
        this.bytes = bytes;
    }
}

class References
{
    public var table :Dictionary = new Dictionary();
    public var ix :uint = 0;
}

class Traits

        }

        // if not, read N bytes
        if ((code >> 1) > 0) {
            var str :String = _ctx.bytes.readUTFBytes(code >> 1);
            _ctx.sRef.push(str);
            return str;
        }
        return "";
    }

    private static function decodeArray () :Array
