Comunidad de diseño web y desarrollo en internet online

bucles for

Citar            
MensajeEscrito el 09 Feb 2009 05:13 pm
hola buenas, que tal
A ver si me pueden ayudar por favor:
Miren, yo tengo un codigo y quiero hacer un bucle con el, que cuando se acabe de ejecutar, vuelva al principio. El codigo en cuestión es:

on (release) {
_global.n = _global.n+1;
if (_global.n == 1) {
_root.ficha7._visible = 1;
_root.ficha6._visible = 0;
_root.ficha5._visible = 0;
_root.ficha4._visible = 0;
_root.ficha3._visible = 0;
_root.ficha2._visible = 0;
_root.ficha1._visible = 0;
_root.ficha8._visible = 0;
}
if (_global.n == 2) {
_root.ficha4._visible = 1;
_root.ficha6._visible = 0;
_root.ficha5._visible = 0;
_root.ficha3._visible = 0;
_root.ficha2._visible = 0;
_root.ficha1._visible = 0;
_root.ficha7._visible = 0;
_root.ficha8._visible = 0;
}
if (_global.n == 3) {
_root.ficha1._visible = 1;
_root.ficha2._visible = 0;
_root.ficha3._visible = 0;
_root.ficha4._visible = 0;
_root.ficha5._visible = 0;
_root.ficha6._visible = 0;
_root.ficha7._visible = 0;
_root.ficha8._visible = 0;
}
if (_global.n == 4) {
_root.ficha6._visible = 1;
_root.ficha5._visible = 0;
_root.ficha4._visible = 0;
_root.ficha3._visible = 0;
_root.ficha2._visible = 0;
_root.ficha1._visible = 0;
_root.ficha7._visible = 0;
_root.ficha8._visible = 0;
}
if (_global.n == 5) {
_root.ficha3._visible = 1;
_root.ficha2._visible = 0;
_root.ficha1._visible = 0;
_root.ficha4._visible = 0;
_root.ficha5._visible = 0;
_root.ficha6._visible = 0;
_root.ficha7._visible = 0;
_root.ficha8._visible = 0;
}
if (_global.n == 6) {
_root.ficha8._visible = 1;
_root.ficha7._visible = 0;
_root.ficha6._visible = 0;
_root.ficha5._visible = 0;
_root.ficha4._visible = 0;
_root.ficha3._visible = 0;
_root.ficha2._visible = 0;
_root.ficha1._visible = 0;
}
if (_global.n == 7) {
_root.ficha5._visible = 1;
_root.ficha6._visible = 0;
_root.ficha7._visible = 0;
_root.ficha8._visible = 0;
_root.ficha4._visible = 0;
_root.ficha3._visible = 0;
_root.ficha2._visible = 0;
_root.ficha1._visible = 0;
}
if (_global.n == 8) {
_root.ficha2._visible = 1;
_root.ficha3._visible = 0;
_root.ficha4._visible = 0;
_root.ficha5._visible = 0;
_root.ficha6._visible = 0;
_root.ficha7._visible = 0;
_root.ficha8._visible = 0;
_root.ficha1._visible = 0;
}
}

Es un codigo que me va sacando fichas, al pulsar en un sitio, la ficha a sacar me la pone visible=1 y las demás visible=0,
y a mi me interesa que cuando termina el codigo, por si se ha dejado alguna ficha en el tintero, empiece de nuevo, pero que las fichas que ya tiene en visible=1 las ignore.

Si me pueden ayudar se lo agradeceria. gracias

Por boryi

79 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 09 Feb 2009 07:12 pm
Hola, para hacer un for puedes hacer esto:

Código ActionScript :

on (release) {
 _global.n++;
 for( var i:Number = 1; i <= 8; i++ )
 {
   _root["ficha"+i]._visible = (i == _global.n);
 }
}


Suerte.

Por LongeVie

Claber

1741 de clabLevel

1 tutorial

Genero:Masculino  

En un lugar, re moto.

firefox
Citar            
MensajeEscrito el 10 Feb 2009 12:58 pm
Esta bien , pro esto solo me hace un bucle, y yo necesito que me haga bucle indefinido
gracias de antemano

Por boryi

79 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 10 Feb 2009 01:57 pm
un bucle infinito te traba el pc, mas bn haslo en un enterframe, asi te lo esta haciendo todo el tiempo como dices q necesitas

Por el_putas

58 de clabLevel



 

firefox
Citar            
MensajeEscrito el 10 Feb 2009 07:13 pm
Hola, como lo tienes todo en un evento onRelese(click) entonces supuse que lo que necesitabas era hacer eso cada vez que se presionaba dicho boton. pero ahora me doy cuenta que necesitas hacerlo repetidamente, entonces usaremos onEnterFrame, tampoco te recomiendo el uso de _global para declarar variables, debes buscar otra alternativa.

Código ActionScript :

onClipEvent(enterFrame)
{
 if( _global.n >= 8 ) _global.n = 0; 
 _global.n++;
 for( var i:Number = 1; i <= 8; i++ ) 
 { 
   _root["ficha"+i]._visible = (i == _global.n); 
 } 
} 


Suerte.

Por LongeVie

Claber

1741 de clabLevel

1 tutorial

Genero:Masculino  

En un lugar, re moto.

firefox

 

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