Código ActionScript :
// -- posición donde se cargará la primera imagen x = 0; y = 0; // -- ancho y alto de la imagen más 5 pixeles de espacio ancho = 68; alto = 68; // -- numero de columnas num_columnas = 10; // -- creo un nuevo objeto XML miXML = new XML(); // -- ignorar espacios miXML.ignoreWhite = true; // -- proceso si la carga tuvo éxito miXML.onLoad = function(succes) { if (succes) { // -- por cada nodo hijo del nodo principal... for (var i = 0; i < this.firstChild.childNodes.length; i++) { // -- delaro una variable que recoje el atributo del nodo (nombre de la imagen) thumb = this.firstChild.childNodes[i].attributes.id; // -- creo un clip de película vacio holder_mc = createEmptyMovieClip("holder_mc" + i, i + 100); // -- creo un clip de película vacio item = holder_mc.createEmptyMovieClip("diapo" + i, i + 100); // texto dinamico _root.holder_mc.createTextField("my_txt"+i, 1, 0, 25, 68, 20); _root.holder_mc["my_txt" + i].text = this.firstChild.childNodes[i].attributes.nom; _root.holder_mc["my_txt" + i].wordWrap = true; var my_fmt:TextFormat = new TextFormat(); my_fmt.align = "center"; my_fmt.font = "Arial"; my_fmt.size = 11; _root.holder_mc["my_txt" + i].setTextFormat(my_fmt); _root.holder_mc["my_txt" + i]._visible = false; item.loadMovie(thumb); // -- indico posición x - y holder_mc._x = x; holder_mc._y = y; // -- se crea una variable que contiene la url correspondiente holder_mc.url = this.firstChild.childNodes[i].attributes.url; // -- abrir url al hacer clic holder_mc.onRelease = function() { getURL(this.url); }; holder_mc.onRollOver = function (){ this._alpha = 20; _root.holder_mc["my_txt" + i]._visible = false; }; holder_mc.onRollOut = function (){ this._alpha = 100; }; // -- incremento el valor de x para la siguiente imágen x += ancho; // -- incremento en 1 el número de columnas columna += 1; // -- ruptura de control, control de número de columnas if (columna == num_columnas) { columna = 0; x -= (ancho * num_columnas); y += alto; } } } }; // -- cargar XML miXML.load("productos.xml");
Código XML :
<?xml version="1.0" encoding="iso-8859-1"?> <imagenes> <imagen id="imagenes-productos/1.jpg" url="http://www.sitiowebprimero.com" nom="productoprimero"/> <imagen id="imagenes-productos/2.jpg" url="http://www.sitiowebsegundo.com" nom="productosegundo"/> </imagenes>