Hi, need to use an array with properties. In Flash I'm used to write something like: Code (csharp): _array = new Array(); _array[0] = {a:"a_value", b:100} trace(_array[0].a+" - "+_array[0].b) If I'm right I've to use an hashtable, so I've tried this: Code (csharp): var _array = new Hash(); _array = {"a" : "a_value", "b": "100"}; But I get this error: Code (csharp): No appropriate version od 'Boo.Lang.Hash' for the argument list '()' was found. I've tried other ways but with no luck. Where is my mistake? Thanks Alessandro
I am not sure, but I believe new Hash() creates a .Net Hash object, which is part of System.Security.Policy. I believe what you want is just Code (csharp): _array = {"a" : "a_value", "b": "100"};
Right! It's so simple! Code (csharp): _array = new Array(); _array[0] = {"a" : "a_value", "b": "100"}; _array[1] = {"a" : "a2_value", "b": "200"}; _array[2] = {"a" : "a3_value", "b": "300"}; // Display something Debug.Log(_array[0]["a"]); Debug.Log(_array[1]["a"]); Debug.Log(_array[2]["a"]);
I've been exploring JavaScript associative arrays / hash tables. Here's some working examples with notes. Code (csharp): // ** using a {} constructor like Flash public var connectorObj: Hashtable = {"a": true, "b": false}; for (key in connectorObj.Keys) { Debug.Log ("connectorObj:" + connectorObj[key]); } - Members cannot be strict typed - Members cannot be exposed to the inspector Code (csharp): // ** extending the Hashtable class class Connector extends Hashtable { var a: boolean; var b: boolean; } public var connectorClass: Connector = new Connector(); connectorClass.Add("a", true); connectorClass.Add("b", false); for (key in connectorClass.Keys) { Debug.Log ("connectorClass:" + connectorClass[key]); } - Members can be strict typed - Members can be exposed to the inspector Code (csharp): // ** using a Hashtable constructor public var connectHash: Hashtable = new Hashtable(); connectHash.Add("a", true); connectHash.Add("b", false); for (key in connectHash.Keys) { Debug.Log ("connectHash:" + connectHash[key]); } - Members cannot be strict typed - Members cannot be exposed to the inspector It seems to me that using a class gives me the most desirable outcome.
I've tried about 8 or 9 different variations on the Hashtable and this (connectorClass) was the first one I got working (for my purposes). Thanks Proto! This was a huge help!