                 if (ii > 0) {
                     s += ", ";
                 }
-                s += (ii + ": " + toString(arr[ii]));
+                s += (ii + ": " + toString(arr[ii], refs));
             }
             return "Array(" + s + ")";
 

                if (s.length > 0) {
                    s += ", ";
                }
                s += prop + "=>" + toString(obj[prop]);
            }
            return "Object(" + s + ")";


    /**
     * Nicely format the specified object into a String.
     */
    public static function toString (obj :*, refs :Dictionary = null) :String
    {
        if (obj == null) { // checks null or undefined
            return String(obj);
        }

        if (refs == null) {
            refs = new Dictionary();

        } else if (refs[obj] !== undefined) {
            return "[cyclic reference]";
        }
        refs[obj] = true;

        var s :String;
        if (obj is Array) {
