Pero gracias por postear el código que seguro que algún valiente se hace con el.
Rafael Martínez
www.fabricanet.com
----- Original Message ----- From: "Andrés González Aragón" <[EMAIL PROTECTED]>
To: <asnativos@5dms.com>
Sent: Monday, April 18, 2005 11:22 AM
Subject: RE: [ASNativos] array 2 dimenciones
Yo hace tiempo desarrolle una clasesita para manejo de Arrays de 2 dimensiones, las clases worldElement y WorldElementsLibrary no sion más que un contenedor y un tipo de datos, solo se trataría de modificar eso para tu uso ahí te va:
import worldElement; import WorldElementsLibrary class Parsers { //----DEFINICIÓN DE VARIABLES var swFile; //----CONSTRUCTOR function Parsers() { } //----GET & SET //T_ARRAY static function get t_array():Array { return create2dArray(15, 15); } /////////////////////////////// //----FUNCIONES----// ////////////////////////////// //----CREATE 2D ARRAY static function create2dArray(w:Number, h:Number) { //Definición var _array:Array = new Array(h); //Bucle for (var i = 0; i<h; i++) { var int_array:Array = new Array(w); for (var j = 0; j<w; j++) { int_array[j] = 0; } _array[i] = int_array; } //Salida return _array; } //----MATRIX TO COORDS static function matrixToCoords(matrix_array:Array):Array { //Definición var coords_array:Array = new Array(); //Bucle for (var i = 0; i<matrix_array.length; i++) { for (var j = 0; j<matrix_array[i].length; j++) { if (Number(matrix_array[i][j]) != 0) { coords_array.push({x:j, y:i, z:Number(matrix_array[i][j])}); } } } //Salida return coords_array; } //----COORDS TO MATRIX static function coordsToMatrix(coords_array:Array, w:Number, l:Number):Array { //Definición //definir arr, contiene una matriz2d creada a partir del largo y ancho //que marcan los puntos del arreglo var arr:Array = create2dArray(w, l); //Bucle, se agregan el punto (coordenada) ' z ' a su respectiva posiciones en cada uno de los miembros del array[array] for (var i = 0; i<coords_array.length; i++) { var element = coords_array[i]; arr[element.y][element.x] = 1; for (var fuck in coords_array[i]) { //_root.textArea.text += "\nelement["+fuck+"] :"+coords_array[i][fuck]+"\n"; } } for (var i = 0; i<l; i++) { for (var n = 0; n<l; n++) { arr[i][n] != 1 ? arr[i][n]=0 : 0; } } //_root.textArea.text += "\n"; //debugeo trace("---arr---"); trace(arr); //Salida return arr; } //----ROTATE COORDS ARRAY static function rotateCoordsArray(crds_array:Array, oriented:String, w:Number, h:Number) { var r_array:Array = coordsToMatrix(crds_array, w, h); for (var lar = 0; lar<r_array.length; lar++) { //_root.textArea.text += "r_array"+lar+" :: "+r_array[lar]; } r_array = rotateArray(r_array, oriented); r_array = matrixToCoords(r_array); return r_array; } //----ADD NULL ARRAY static function addNullArr(_array:Array, wid:Number, hei:Number):Array { //Definir ' formato ' introduciendo una Matriz 2d utilizando las medidas deseadas var format:Array = create2dArray(wid, hei); for (var name in _array) { for (var each in _array[name]) { format[name][each] = _array[name][each]; } } return format; } //----DELETE NULL ARRAY static function deleteNullArr(_array:Array):Array { var large:Number = 0; var lastSum:Boolean = false; for (var name in _array) { var sum:Number = 0; for (var each in _array[name]) { sum += _array[name][each] == -1 ? 1 : _array[name][each]; if (_array[name][each] == 0 && sum == 0) { //trace("°°° "+name+" ° "+_array[name][each]); _array[name].pop(); } } if (sum == 0 && !lastSum) { _array.pop(); } else { lastSum = true; } large<_array[name].length ? large=_array[name].length : large=large; } for (var eacht = 0; eacht<_array.length; eacht++) { if (_array[eacht].length<large) { var it = large-_array[eacht].length; for (var q = 0; q<it; q++) { _array[eacht].push(0); } } //trace("|"+_array[eacht]+"| "+_array[eacht].length); } return _array; } //----ROTATE ARRAY static function rotateArray(_array:Array, cardinal:String):Array { if (cardinal == "E") { //izq var N_array:Array = create2dArray(_array.length, _array[0].length); for (var i = 0; i<_array.length; i++) { for (var m = 0; m<_array[i].length; m++) { N_array[m][i] = _array[i][m]; } } N_array.reverse(); } else if (cardinal == "W") { //der var N_array:Array = create2dArray(_array.length, _array[0].length); for (var i = 0; i<_array.length; i++) { for (var m = 0; m<_array[i].length; m++) { N_array[m][i] = _array[i][m]; } } for (var n = 0; n<N_array.length; n++) { N_array[n].reverse(); } } else if (cardinal == "S") { //turn var N_array:Array = create2dArray(_array[0].length, _array.length); for (var o = 0; o<N_array.length; o++) { N_array[o] = _array[o].reverse(); } N_array.reverse(); } else if (cardinal == "N") { //no cambia N_array = _array; } return N_array; } //----GENERATE XML static function generateXml(o:worldElement):String { var line:String; var shape:Array = o.wo_shape; var access:Array = o.wo_access; var ep_array:Array; deleteNullArr(access); deleteNullArr(shape); shape = rotateArray(shape, o.wo_oriented); o.wo_width = shape[0].length; o.wo_length = shape.length; access = addNullArr(access, o.wo_width, o.wo_length); access = rotateArray(access, o.wo_oriented); line = "<OBJECT id=\""+o.wo_id+"\" faces=\""+o.wo_faces+"\" tooltip=\""; line += o.wo_ttip+"\" width=\""; line += o.wo_width+"\" height=\""; line += o.wo_length+"\" desc=\""; line += o.wo_desc+"\" type=\""; line += o.wo_prefix.toUpperCase(); line += "\">"; // line += "<SHAPE>"; for (var j = 0; j<shape.length; j++) { !shape[j] ? shape[j]=0 : null; line += "<ROW>"; for (var l = 0; l<shape[j].length; l++) { line += shape[j][l]=shape[j][l] == -1 ? 0 : shape[j][l].toString(); } line += "</ROW>"; } // line += "</SHAPE>"; // line += "<ACCESS>"; // for (var k = 0; k<o.wo_length; k++) { line += "<ROW>"; for (var m = 0; m<o.wo_width; m++) { line += Math.abs(Number(access[k][m])-1).toString(); } line += "</ROW>"; } // line += "</ACCESS>"; // line += "<ASSETS>"; // //line += "<object id=\"bartittle\" pos=\"123,145\" multilang=\"true\"/>"; //line += "<object id=\"door\" pos=\"148,345\"/>"; // line += "</ASSETS>"; // line += "<LINK command=\""; line += o.wo_linkCmd+"\" />"; // line += "<ENTRYPOINT>"; // ///////////////// ep_array = rotateCoordsArray(o.wo_epoint, o.wo_oriented, o.wo_width, o.wo_length); for (var n in ep_array) { line += "<AccessPoint x=\""; line += String(ep_array[n].x); line += "\" y=\""; line += String(ep_array[n].y); line += "\" entry=\"N,S,E,W\"/>"; } //*/ line += "</ENTRYPOINT>"; // line += "</OBJECT>"; line = unescape(line); //_root.textArea.text += "\n******\n"+access; return line; } //----PARSE XML static function parseXml(str:String, route:String,wel:WorldElementsLibrary) { //DEFINICIÓN DE VARIABLES var xml:XML = new XML(); var childs_array:Array; var accChilds_array:Array; var reorient:String; var r:worldElement; xml.ignoreWhite = true; //WML ONLOAD xml.onLoad = function(success) { set(route+"."+xml.firstChild.attributes.id, new worldElement(xml.firstChild.attributes.id, xml.firstChild.attributes.tooltip, xml.firstChild.attributes.faces, xml.firstChild.attributes.width, xml.firstChild.attributes.height, xml.firstChild.attributes.desc, xml.firstChild.attributes.type)); if (eval(route+"."+xml.firstChild.attributes.id) instanceof worldElement) {
wel.addWorldElement(eval(route+"."+xml.firstChild.attributes.id), _root.moviesPath+"/"+eval(route+"."+xml.firstChild.attributes.id).wo_pre fix+"\\"+xml.firstChild.attributes.id+".swf"); _root.textArea.text+="\n_root.moviesPath desde Parsers ::"+_root.moviesPath childs_array = xml.firstChild.firstChild.childNodes; accChilds_array = xml.firstChild.firstChild.nextSibling.childNodes; var wo:worldElement = eval(route+"."+xml.firstChild.attributes.id); var shape_array:Array = create2dArray(wo.wo_width, wo.wo_length); var access_array:Array = create2dArray(wo.wo_width, wo.wo_length); for (var i = 0; i<childs_array.length; i++) { shape_array[i] = String(childs_array[i].firstChild).split(""); access_array[i] = String(accChilds_array[i].firstChild).split(""); } ///////// if (wo.wo_oriented == "W") { reorient = "E"; } else if (wo.wo_oriented == "E") { reorient = "W"; } else { reorient = wo.wo_oriented; } shape_array = rotateArray(shape_array, reorient); access_array = rotateArray(access_array, reorient); for (var i = 0; i<access_array.length; i++) { for (var n = 0; n<access_array.length; n++) { access_array[j][n] = Math.abs(Number(access_array[j][n])-1); } } shape_array = addNullArr(shape_array, 15, 15); access_array = addNullArr(access_array, 15, 15); ///////// for (var j = 0; j<shape_array.length; j++) { for (var k = 0; k<shape_array[i].length; k++) { shape_array[j][k] = Number(shape_array[j][k]); access_array[j][k] = Number(access_array[j][k]); if (shape_array[j][k] != 0) { if (shape_array[j][k] == null || shape_array[j][k] == undefined || shape_array[j][k] == "") {
shape_array[j][k] = 0; } } } } wo.wo_shape = shape_array; wo.wo_access = access_array; var epoint_array:Array = new Array(); for (var aNode = xml.firstChild.firstChild; aNode != null; aNode=aNode.nextSibling) { if (aNode.nodeName == "LINK") { wo.wo_linkCmd = aNode.attributes.command; } if (aNode.nodeName == "ENTRYPOINT") { for (var bNode = aNode.firstChild, n = 0; bNode != null; bNode=bNode.nextSibling, n++) { var obj:Object = new Object(); obj.x = bNode.attributes.x; obj.y = bNode.attributes.y;
epoint_array.push(obj); } } } wo.wo_epoint = rotateCoordsArray(epoint_array, reorient, wo.wo_width, wo.wo_length); } }; //LOAD XML xml.load(str); } //----SLASHES static function Slashes(input):String { var parsed = ""; var _array:Array = input.split("\\"); for (var i = 0; i<_array.length-1; i++) { parsed += _array[i]+"/"; } parsed += _array[_array.length-1]; return parsed; } //----OR_DECRYPT static function or_decrypt(binValue:Number, elements:Number):Array { var resultArray:Array = new Array(); var j:Number = 1; if (elements == null || elements<1) { var elements = 1; } for (var i = 0; i<elements; i++) { var decResult = ((binValue | j) == binValue); //resultArray.push(decResult+"("+j+")-"+i); resultArray.push(decResult); j = (j << 1); } return resultArray; } //----OR_ENCRYPT static function or_encrypt(elements:Array):Number { var _array:Array = new Array(elements.length); var j:Number = 1; var r:Number = 0; for (var i = 0; i<elements.length; i++) { _array[i] = elements[i] ? (j << i) : 0; r += _array[i]; } delete j; delete _array; return r; } } ---------------------------------- Lista ASNativos:asnativos@5dms.com http://www.5dms.com/listas ----------------------------------
---------------------------------- Lista ASNativos:asnativos@5dms.com http://www.5dms.com/listas ----------------------------------