A Flash Developer Resource Site

Results 1 to 1 of 1

Thread: Paging XML items in Flash

Hybrid View

  1. #1
    Member
    Join Date
    Mar 2004
    Location
    Argentina
    Posts
    43

    Paging XML items in Flash

    Hi. Guess this is the right room to post this.

    I have been "building" for some time, a group of menues and sub-menues, that get the info from an XML file. I´ve almost done it, but still I have some issues I can´t solve.

    My ActionScript gets the info from the XML, then generates a menu, from which you get more menues when clicking the frist options. You get four options at the beginning. Three of them have no more than 9 items, but one of them has 12 items, which don´t fit in my design. So I need to generate "pages" to divide these items. I got to the point that I can show 9 items and the "Previous-Next" buttons appear below. But I can´t make the buttons work so that the "Next" button shows me the next 9 items or whatever. ¿Any help or tips on this?

    Here´s an example of what I mean: www.escueladeperiodismo.edu.ar/demos/inicio.html

    The XML:

    Code:
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    
    <CATALOGO>
    
    	<SECCION titulo="Sección 1">
    
    		<EMPRESA titulo="Empresa 1">
    			<CARACTERISTICAS nombre="Empresa 1" link="" foto="imgs/trabajo1.jpg" desc="descripción" />
    			<CARACTERISTICAS nombre="" link="www.web1.com.ar" foto="imgs/web1.jpg" desc="descripción" />
    		</EMPRESA>
    
    		<EMPRESA titulo="Empresa 2">
    			<CARACTERISTICAS nombre="" link="www.web2.edu.ar" foto="imgs/trabajo2.jpg" desc="descripción" />
    		</EMPRESA>
    
    		<EMPRESA titulo="Empresa 3">
    			<CARACTERISTICAS nombre="" link="www.web3.com.ar" foto="imgs/trabajo3.jpg" desc="descripción" />
    		</EMPRESA>
    
    		<EMPRESA titulo="Empresa 4">
    			<CARACTERISTICAS nombre="" link="www.web4.com.ar" foto="imgs/web4.jpg" desc="descripción" />
    		</EMPRESA>
    
    		<EMPRESA titulo="Empresa 5">
    			<CARACTERISTICAS nombre="" link="www.web5.com.ar" foto="imgs/web5.jpg" desc="descripción" />
    		</EMPRESA>
    		
    		<EMPRESA titulo="Empresa 6">
    			<CARACTERISTICAS nombre="" link="www.web6.com.ar" foto="imgs/web6.jpg" desc="descripción" />
    		</EMPRESA>
    		
    		<EMPRESA titulo="Empresa 7">
    			<CARACTERISTICAS nombre="Empresa 7" link="" foto="imgs/trabajo7.jpg" desc="descripción" />
    		</EMPRESA>
    		
    		<EMPRESA titulo="Empresa 8">
    			<CARACTERISTICAS nombre="Empresa 8" link="" foto="imgs/trabajo8.jpg" desc="descripción" />
    		</EMPRESA>
    
    	</SECCION>
    
    
    
    	<SECCION titulo="Sección 2">
    
    		<EMPRESA titulo="Empresa 1">		
    			<CARACTERISTICAS nombre="Empresa 1" link="" foto="imgs/trabajo9.jpg" desc="descripción" />
    			<CARACTERISTICAS nombre="Empresa 1" link="" foto="imgs/trabajo10.jpg" desc="descripción" />
    			<CARACTERISTICAS nombre="Empresa 1" link="" foto="imgs/trabajo11.jpg" desc="descripción" />
    			<CARACTERISTICAS nombre="Empresa 1" link="" foto="imgs/trabajo12.jpg" desc="descripción" />
    		</EMPRESA>
    
    		<EMPRESA titulo="Empresa 2">
    			<CARACTERISTICAS nombre="Empresa 2" link="" foto="imgs/trabajo13.jpg" desc="descripción" />
    		</EMPRESA>
    		
    		<EMPRESA titulo="Empresa 3">
    			<CARACTERISTICAS nombre="Empresa 3" link="" foto="imgs/trabajo14.jpg" desc="descripción" />
    			<CARACTERISTICAS nombre="Empresa 3" link="" foto="imgs/trabajo15.jpg" desc="descripción" />
    		</EMPRESA>
    		
    		<EMPRESA titulo="Empresa 4">
    			<CARACTERISTICAS nombre="Empresa 4" link="" foto="imgs/trabajo16.jpg" desc="descripción" />
    			<CARACTERISTICAS nombre="Empresa 4" link="" foto="imgs/trabajo17.jpg" desc="descripción" />			
    		</EMPRESA>
    		
    		<EMPRESA titulo="Empresa 5">
    			<CARACTERISTICAS nombre="Empresa 5" link="" foto="imgs/trabajo17.jpg" desc="descripción" />
    			<CARACTERISTICAS nombre="Empresa 5" link="" foto="imgs/trabajo18.jpg" desc="descripción" />
    		</EMPRESA>
    		
    		<EMPRESA titulo="Empresa 6">
    			<CARACTERISTICAS nombre="Empresa 6" link="" foto="imgs/trabajo19.jpg" desc="descripción" />
    		</EMPRESA>
    		
    		<EMPRESA titulo="Empresa 7">
    			<CARACTERISTICAS nombre="Empresa 7" link="" foto="imgs/trabajo20.jpg" desc="descripción" />
    		</EMPRESA>
    		
    		<EMPRESA titulo="Empresa 8">
    			<CARACTERISTICAS nombre="Empresa 8" link="" foto="imgs/trabajo21.jpg" desc="descripción" />
    		</EMPRESA>
    		
    		<EMPRESA titulo="Empresa 9">
    			<CARACTERISTICAS nombre="Empresa 9" link="" foto="imgs/trabajo22.jpg" desc="descripción" />
    		</EMPRESA>
    		
    		<EMPRESA titulo="Empresa 10">
    			<CARACTERISTICAS nombre="Empresa 10" link="" foto="imgs/trabajo23.jpg" desc="descripción" />
    		</EMPRESA>
    		
    		<EMPRESA titulo="Empresa 11">
    			<CARACTERISTICAS nombre="Empresa 11" link="" foto="imgs/trabajo24.jpg" desc="descripción" />
    		</EMPRESA>
    		
    		<EMPRESA titulo="Empresa 12">
    			<CARACTERISTICAS nombre="Empresa 12" link="" foto="imgs/trabajo25.jpg" desc="descripción" />
    		</EMPRESA>
    
    	</SECCION>
    	
    	
    
    	<SECCION titulo="Sección 3">
    	
    		<EMPRESA titulo="Empresa 1">
    			<CARACTERISTICAS nombre="Empresa 1" link="" foto="imgs/trabajo26.jpg" desc="descripción" />
    		</EMPRESA>
    	
    	</SECCION>
    	
    	
    
    	<SECCION titulo="Sección 4">
    	
    		<EMPRESA titulo="Empresa 1">
    			<CARACTERISTICAS nombre="Empresa 1" link="" foto="imgs/trabajo27.jpg" desc="descripción" />
    		</EMPRESA>
    		
    		<EMPRESA titulo="Empresa 2">
    			<CARACTERISTICAS nombre="Empresa 2" link="" foto="imgs/trabajo28.jpg" desc="descripción" />
    		</EMPRESA>
    		
    		<EMPRESA titulo="Empresa 3">
    			<CARACTERISTICAS nombre="Empresa 3" link="" foto="imgs/trabajo29.jpg" desc="descripción" />
    		</EMPRESA>
    
    	</SECCION>
    
    </CATALOGO>
    The ActionScript:

    Code:
    this._x=25;
    this._y=196;
    
    System.useCodepage = true;
    portfolioXML = new XML();
    portfolioXML.ignoreWhite = true;
    portfolioXML.load("trabajos.xml");
    portfolioXML.onLoad = function(){
    	attacharSecciones()
    }
    
    /*Función para attachar secciones*/
    attacharSecciones=function(){
    	
    	x = 0;
    	y = 0;
    	ancho = 110;
    	alto = 19;
    	num_columnas = 2;
    	columna = 0;
    
    	var catalogo = portfolioXML.firstChild;
    
       	for (var i = 0; i<catalogo.childNodes.length; i++) {
    		var seccion = catalogo.childNodes[i];
          	var secc_mc = attachMovie("seccionID", "bot1"+i, i);
    		secc_mc._x = x;
    		secc_mc._y = y;								
    	  	secc_mc.index_seccion=i;
          	secc_mc.titulo = seccion.attributes.titulo;
    		x += ancho;
    		columna += 1;
    		if (columna == num_columnas){
    			x -= (ancho*num_columnas);
    			y += alto;
    		}
    	}
    	attacharEmpresas(0);
    }
    
    /*Función para attachar empresas*/
    attacharEmpresas=function(index_seccion){
    	
    	createEmptyMovieClip("modEmpresas",200);
    	modEmpresas._x = 0;
    	modEmpresas._y = 70;
    	
    	var catalogo = portfolioXML.firstChild;
        var seccion = catalogo.childNodes[index_seccion];
    	//eliminamos las que hubiera
        j=0
    	var emp=this["bot2"+j]
    	while (emp!=null){
    		emp.removeMovieClip()
    		j++
    	  	emp=this["bot2"+j]
    	}
    	
    	inicio = 0;
    	itemsPorPagina = 9;
    	itemsTotales = seccion.childNodes.length;
    	pages = Math.ceil(itemsTotales/itemsPorPagina);
    	pageclip = 1;
    	
    	if (itemsTotales>9){
    		paginas._visible = true;
    	}
    	else {
    		paginas._visible = false;
    	}
    	
        for (var j = inicio; j<(inicio+itemsPorPagina); j++) {
           var empresa = seccion.childNodes[j];
           var emp_mc = modEmpresas.attachMovie("empresaID", "bot2"+j, j+100);
           emp_mc._y = 20*j;
           emp_mc.titulo = empresa.attributes.titulo;
    	   emp_mc.index_seccion = index_seccion;
    	   emp_mc.index_empresa = j;
    	}
    	
    	attacharCaracteristicas(index_seccion,0);
    }
    
    /*Función para attachar caracterÃ*sticas*/
    attacharCaracteristicas=function(index_seccion,index_empresa){
    	
    	createEmptyMovieClip("modCaracteristicas",300);
    	modCaracteristicas._x = 235;
    	modCaracteristicas._y = 260;
    	
    	var catalogo = portfolioXML.firstChild;
        var seccion = catalogo.childNodes[index_seccion];
        var empresa = seccion.childNodes[index_empresa]
    	//eliminamos las que hubiera
        j=0
    	var caract = this["bot3"+j]
    	while (caract != null){
    		caract.removeMovieClip()
    		j++
    	  	caract = this["bot3"+j]
    	}
    	for (var k = 0; k<empresa.childNodes.length; k++) {
    		var caracteristicas = empresa.childNodes[k];
            var caract_mc = modCaracteristicas.attachMovie("caracteristicasID", "bot3"+k, k+200);
            caract_mc._y = -22*k;
    		caract_mc.nombre = caracteristicas.attributes.nombre;
    		caract_mc.link = caracteristicas.attributes.link;
    		caract_mc.desc = caracteristicas.attributes.desc;
    		caract_mc.foto = caracteristicas.attributes.foto;
    		img._x = 256;
            img._y = -56;	
    	}
    }
    
    tapaMenu=function(){
    	attachMovie("tapa", "tapa", 400);
    	tapa._x=0;
    	tapa._y=70;
    }
    
    MovieClip.prototype.botOff = function() {
    	for (i=0; i<100; i++) {
    		this["bot"+i].gotoAndStop(1);
    	}
    };
    
    stop();
    The problem is in the "attacharEmpresas" function.

    Thanks in advance.
    Last edited by Hamah; 07-02-2007 at 11:07 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center