Comunidad de diseño web y desarrollo en internet online

Codigo botones de xml

Citar            
MensajeEscrito el 02 Nov 2009 09:20 pm
Estoy montando un sistema de noticias con xml

Código :

function cargarXML() {
   // xml="proyectos.xml";
   obj_xml.load("agenda.xml");
   trace("cargando xml")
}

News = new Array();
Noticias = new Array();
Enlaces = new Array();
Fotos = new Array();
Pdfs = new Array();

var obj_xml:XML = new XML();
obj_xml.ignoreWhite = true;
cargarXML();
obj_xml.onLoad = function(exito) {
   if (exito) {
      trace("xml cargado")
      agenda = this.firstChild.childNodes;
      vTotal = agenda.length;
      for (var i=0; i<vTotal; i++) {
        //---------------- cargamos variables del xml
        News[i] = obj_xml.firstChild.childNodes[i].attributes.cabecera;
        Noticias[i] = obj_xml.firstChild.childNodes[i].attributes.texto;
   Enlaces[i] = obj_xml.firstChild.childNodes[i].attributes.enlace;
   Fotos[i] = obj_xml.firstChild.childNodes[i].attributes.foto;
   Pdfs[i] = obj_xml.firstChild.childNodes[i].attributes.pdf; 
      }
   }
};


El boton enlaces debe de leer la direccion guardada, para luego que cada boton envie a un enlace, pero no consigo crear un for para que asigne a cada boton.

Código :

for(n=0; n < News.length; n++) {
 url[n]="http://" + link["btn_enlaces"+n].txt.text;
 this.link["btn_enlaces"+n].onRelease = function (){
   getURL(url[n],"_blank");
   trace (url[n]);
      }
}


Dando como resultado undefined.

Sin embargo poniendolo manualmente si que me enlaza coorectamente.

Código :

url1="http://" + link["btn_enlaces"+0].txt.text;
     this.link["btn_enlaces"+0].onRelease = function (){
        getURL(url1,"_blank");
        trace (url1);
      }


Alguna ayuda

Por Idearis

19 de clabLevel



 

firefox
Citar            
MensajeEscrito el 02 Nov 2009 10:19 pm
y si usas un codigo desde la capa


for(n=0; n < News.length; n++) {
var url:String ="http://" + link["btn_enlaces"+n].txt.text;
//creo una variable para cargar las rutas de los botones.
var btnLink:MovieClip = eval("boton_a_enlazar"+n);
//aca le asigno las funciones a cada enesimo boton.
btnLink.onRelease = function (){
getURL(url[n],"_blank");
trace (url[n]);
}
}

prueba con algo asi.

Por esavoy

12 de clabLevel



 

firefox
Citar            
MensajeEscrito el 03 Nov 2009 06:44 pm
Cuando entra a la función onRelease de algun boton, el valor de n no esta definido porque lo esta tomando como variable local, además si lo defines como variable global, tomaria el ultimo valor asignado y no te serviria.

Lo que yo hago es guardar el indice como variable local del boton y luego usarla, o guardar directamente la url como variable local del boton.

Código :

for(n=0; n < News.length; n++) {
   url[n]="http://" + link["btn_enlaces"+n].txt.text;
   this.link["btn_enlaces"+n].n = n;
   this.link["btn_enlaces"+n].url = url[n];
   this.link["btn_enlaces"+n].onRelease = function (){
      getURL(this.url,"_blank");   // esta linea usa la url local del boton
      getURL(url[this.n],"_blank"); // esta linea usa el indice n guardado para extraer la url del arreglo.
      trace (this.url + " -- " + url[this.n]);
   }
}

pruebalo y nos cuentas...

Por gabynufe

Claber

446 de clabLevel



 

México, D.F.

firefox
Citar            
MensajeEscrito el 09 Nov 2009 11:17 am
hola amigos tengo un problema de actionscript pues es una botonera en una animacion de tres en tres entran tras botones y luego otros tres los botones llevan a URL distintos,
el problema es que los primeros tres me funcionan pero cuando monto el codigo para los otros tres sale un error y no corre ni la pelicula
QUE PODRA SER!!!!!!!!!

Por duvan121212

2 de clabLevel



 

firefox
Citar            
MensajeEscrito el 09 Nov 2009 11:18 am
EL CODIGO QUE ESTOY USANDO ES ESTE.

transOmnia.addEventListener(MouseEvent.CLICK, link1);
function link1(event:MouseEvent):void {
navigateToURL(new URLRequest ("http://www.tacom.de/shop/"));
}


transPixon.addEventListener(MouseEvent.CLICK, link2);
function link2(event:MouseEvent):void {
navigateToURL(new URLRequest ("http://www.tacom.de/handy_details/12082/Samsung_Pixon_12_M8910_.html"));
}


transCorby.addEventListener(MouseEvent.CLICK, link3);
function link3(event:MouseEvent):void {
navigateToURL(new URLRequest ("http://www.tacom.de/shop/"));
}

Por duvan121212

2 de clabLevel



 

firefox
Citar            
MensajeEscrito el 09 Nov 2009 11:20 am
PERO CUANDO QUIERO REPETIR EL CODIGO PARA LOS SIGUIENTES TRES BOTONES LE CAMBIO LOS NOMBRES DE INSTANCIA DE LOS BOTONES, LOS URL Y LA FUNCION PERO NO ME FUNCIONA

Por duvan121212

2 de clabLevel



 

firefox
Citar            
MensajeEscrito el 09 Nov 2009 11:28 am
alguien me podria AYUDAR!!!!!!!!

Por duvan121212

2 de clabLevel



 

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.