Comunidad de diseño web y desarrollo en internet online

Problema con Get URL y array

Citar            
MensajeEscrito el 30 Jul 2011 07:40 pm
Hola que tal, soy nuevo por aquí y en Actionscript 3.0 tambien, así que les agradecería mucho si me pueden ayudar con un problema que tengo.

Tengo un sitio hecho en PhP pero el menú está hecho en Actionscript 3.0 de forma dinámica. Todo funciona bastante bien pero cuando hago click en algun boton me envia a todas las direcciones del Array...

Abajo dejo el código a ver si alguien me puede decir que burrada estoy haciendo :-P

Gracias!

public class Botones extends MovieClip
{
var links = ["http://www.miweb.net/index.html", "http://www.miweb.net/html/estrenos.php", "http://www.miweb.net/html/promociones.php", http://www.miweb.net/pruebas/html/conocenos.php", "http://www.miweb.net/pruebas/html/contacto.php"];


public function Botones() {
var etiquetas = ["Home", "Próximas Cosas", "Promociones", "Conócenos", "Contacto" ];

var nX = 0;

for ( var i = 0; i < etiquetas.length; i++) {
var miBoton:MovieClip = new Boton();
addChild( miBoton );
miBoton.txtEtiqueta.autoSize = "left";
miBoton.txtEtiqueta.text = etiquetas[i];
miBoton.mcFondo.width = miBoton.txtEtiqueta.width;
miBoton.txtEtiqueta.x = ( miBoton.mcFondo.width - miBoton.txtEtiqueta.width ) / 2;
miBoton.txtEtiqueta.y = ( miBoton.mcFondo.height - miBoton.txtEtiqueta.height ) / 2;
miBoton.buttonMode = true;
miBoton.mouseChildren = false;
miBoton.x = nX;
nX += miBoton.width + 2;
miBoton.mcRombo.alpha = 0;
miBoton.mcRombo.x = miBoton.mcFondo.width / 2 - miBoton.mcFondo.width / 2 + 24.875;
miBoton.mcRombo.y = miBoton.mcFondo.height /2 - miBoton.mcRombo.height / 2 + 9.875;

TweenMax.from( miBoton, 0.5, { alpha: 0.5, scaleY: -2, delay: i * 0.2, ease: Strong.easeOut } );

miBoton.addEventListener( MouseEvent.MOUSE_OVER, button_over );
miBoton.addEventListener( MouseEvent.MOUSE_OUT, button_out );
miBoton.addEventListener( MouseEvent.CLICK, button_click );
}
}

function button_over(evento) {
TweenMax.to(evento.target.mcRombo, 0.5, { rotation:720, scaleX:1, scaleY:1, alpha: 1, ease: Strong.easeInOut } );
TweenMax.to(evento.target.mcFondo, 0.5, {colorTransform:{tint:0xeb1c24, tintAmount:0.5}});
TweenMax.to( evento.target.mcFondo, 0.8, { alpha: 1, scaleY: 1.15, ease: Strong.easeOut } );
}

function button_out(evento) {
TweenMax.to(evento.target.mcRombo, 0.8, { alpha: 0, rotation:720, scaleX:0, scaleY:0,ease: Strong.easeInOut } );
TweenMax.to(evento.target.mcFondo, 0.5, {colorTransform:{tint:0x750004, tintAmount:0.5}});
TweenMax.to( evento.target.mcFondo, 0.2, { alpha: 1, scaleY: 1, ease: Strong.easeIn } );
}

function button_click(evento) {
trace( evento.target, evento.currentTarget );
trace( evento.target.link );
var url = links;
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, '_self');
} catch (e:Error) {
trace("Error occurred!");
}
}

}

}

Por O5kr

3 de clabLevel



 

firefox
Citar            
MensajeEscrito el 31 Jul 2011 12:30 am
mira, no soy un experto en as3 pero lo que yo analice es que tu variable "links" es de tipo Array...
"private var links:Array = [...];"

Código ActionScript :

public class Botones extends MovieClip
{
var links = ["http://www.miweb.net/index.html", "http://www.miweb.net/html/estrenos.php", "http://www.miweb.net/html/promociones.php", http://www.miweb.net/pruebas/html/conocenos.php", "http://www.miweb.net/pruebas/html/contacto.php"]; 


y aqui lo que haces es pasar tu arreglo "links" a la variable "url" que este vendria siendo lo mismo que "links".. y este arreglo se lo mandas a URLRequest, por eso cuando das CLICK, te manda todos las direcciones que pusiste dentro de "links"...

'..algo que si me dejo en duda, es que no sabia que podia mandar una serie de links, osea, un arreglo dentro del URLRequest... :S '

Código ActionScript :

function button_click(evento) {
trace( evento.target, evento.currentTarget );
trace( evento.target.link );
var url = links;
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, '_self');
} catch (e:Error) {
trace("Error occurred!");
}
} 


una solucion para mi, viendo tu code....

Código ActionScript :

<.....

for ( var i = 0; i < etiquetas.length; i++) {
var miBoton:MovieClip = new Boton();
addChild( miBoton ); 
//AQUI AGREGAS UNA VARIABLE DINAMICA que tendra el link de cada boton
miBoton.myLink = links[i]; // asi cada boton tendra su propio link
..... // el resto de tu codigo.

.....>



y en la parte de abajo, en la funcion click...

Código ActionScript :

function button_click(evento:Event) {
var request:URLRequest = new URLRequest(evento.currentTarget.myLink);
try {
navigateToURL(request, '_self');
} catch (e:Error) {
trace("Error occurred!");
} 


var request:URLRequest = new URLRequest(evento.currentTarget.myLink);
ahi lo que estoy haciendo es llamar la variable dinamica que cree dentro del MovieClip "Boton" y este se manda al URLRequest, asi solo mando a llamar el link de cada boton..

espero me haya dado a entender, saludos

Por ilvxor

11 de clabLevel



 

c++ as3

firefox

 

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