llevo tiempo con una galería en flash que coge los datos de un XML, y no consigo terminarlo.
La galería la crea perfectamente, igual que el menú, el problema es cuando quiero dar acción a los botones del menú, no consigo hacerlo funcionar. Lo que quiero es que al clicar en cada botón se abra la galería correspondiente.
Este es el xml:
Código :
<?xml version="1.0" encoding="iso-8859-1"?> <galeria> <fotos titulo="Retrato"> <img nom_xml="fotos/retratos/retr.1.jpg"/> <img nom_xml="fotos/retratos/retr.2.jpg"/> <img nom_xml="fotos/retratos/retr.3.jpg"/> <img nom_xml="fotos/retratos/retr.4.jpg"/> <img nom_xml="fotos/retratos/retr.5.jpg"/> <img nom_xml="fotos/retratos/retr.6.jpg"/> <img nom_xml="fotos/retratos/retr.7.jpg"/> <img nom_xml="fotos/retratos/retr.8.jpg"/> <img nom_xml="fotos/retratos/retr.9.jpg"/> <img nom_xml="fotos/retratos/retr.10.jpg"/> <img nom_xml="fotos/retratos/retr.11.jpg"/> <img nom_xml="fotos/retratos/retr.12.jpg"/> <img nom_xml="fotos/retratos/retr.13.jpg"/> <img nom_xml="fotos/retratos/retr.14.jpg"/> <img nom_xml="fotos/retratos/retr.15.jpg"/> <img nom_xml="fotos/retratos/retr.16.jpg"/> </fotos> <fotos titulo="Boda"> <img nom_xml="fotos/boda/01.jpg"/> <img nom_xml="fotos/boda/02.jpg"/> <img nom_xml="fotos/boda/03.jpg"/> <img nom_xml="fotos/boda/04.jpg"/> <img nom_xml="fotos/boda/05.jpg"/> <img nom_xml="fotos/boda/06.jpg"/> <img nom_xml="fotos/boda/07.jpg"/> <img nom_xml="fotos/boda/08.jpg"/> <img nom_xml="fotos/boda/09.jpg"/> <img nom_xml="fotos/boda/10.jpg"/> <img nom_xml="fotos/boda/11.jpg"/> <img nom_xml="fotos/boda/12.jpg"/> <img nom_xml="fotos/boda/13.jpg"/> <img nom_xml="fotos/boda/14.jpg"/> <img nom_xml="fotos/boda/15.jpg"/> <img nom_xml="fotos/boda/16.jpg"/> </fotos> </galeria>
Y este es el código del fla:
Código :
//--Definir variables inciales --//
var lista_xml:XML = new XML();
lista_xml.ignoreWhite = true;
var cargador_mcl:MovieClipLoader = new MovieClipLoader();
cargador_mcl.addListener(this);
var img_w:Number = 400;//Ancho de las imagenes
var img_h:Number = 500;//Alto de las imagenes
var img_n:Number = 3;//Numero de imagenes que se mostraran
var img_s:Number = 115;//Separacion entre las imagenes
var gal_x:Number = -178.3;//Posicion en X de la galeria
var gal_y:Number = 117.0;//Posicion en Y de la galeria
//-- Crear la galeria --//
var galeria:MovieClip = this.createEmptyMovieClip("galeria", 120);
galeria.createEmptyMovieClip("miniaturas", 0);
galeria.miniaturas.setMask( galeria.mascara );
galeria._x = this.gal_x;
galeria._y = this.gal_y;
//-- Carga XML --//
lista_xml.onLoad = function( ok:Boolean )
{
if( ok )//Si se cargo correctamente
{
crearImagenes();
}
else trace("No se pudo cargar el XML");
}
lista_xml.load("fotos.xml");
//-- Crear las imagenes --//
function crearImagenes( Void ):Void
{
//Variables auxiliares
var aux:MovieClip;
var img_aux:String;
var url_aux:String;
var opciones:Array = lista_xml.firstChild.childNodes;
var indice:Number;
for(i = 0; i < opciones.length; i++) { // Comienza a repetirse esta parte del código, tantas veces como elementos hay en el XML
_root.menu.menu2.mcBoton.attachMovie("menubotonclip", "boton"+i, _root.menu.menu2.mcBoton.getNextHighestDepth()); // Creamos un MC copiado del original, tal como explicamos anteriormente
_root.menu.menu2.mcBoton["boton"+i]._x = 150; // Su posición horizontal sera a 50 px
_root.menu.menu2.mcBoton["boton"+i]._y = 60 + (i * 25); // Su posición vertical va cambiando como explicamos hace un momento
_root.menu.menu2.mcBoton["boton"+i].texto = opciones[i].attributes.titulo; // Le asignamos el correspondiente texto al botón
_root.menu.menu2.mcBoton["boton"+i].linkurl = opciones[i]; // Le asignamos el correspondiente Link a botón
_root.menu.menu2.mcBoton["boton"+i].linkurl = i
_root.menu.menu2.mcBoton["boton"+i].onRelease = function(){
cargaXML(_root.menu.menu2.mcBoton["boton"+i].indice); // tienes que crear una funcion que lea la estructura XML (yo la he llamado cargaXML)
}
}
for( var i:Number = 0, l:Number = lista_xml.firstChild.childNodes[1].childNodes.length; i < l; i++)
{
aux = this.crearImagen( i );
img_aux = lista_xml.firstChild.childNodes[0].childNodes[i].attributes.nom_xml;
cargador_mcl.loadClip( img_aux, aux.thumb_mc );
}
}
function crearImagen( index:Number ):MovieClip
{
//Clips
var clip:MovieClip = this.galeria.miniaturas.createEmptyMovieClip("mc_" + index, index);
clip.createEmptyMovieClip("thumb_mc", 0)
//Posicion
clip.index = i;
clip._y = (this.img_w + this.img_s) * index;
return clip;
}
