Comunidad de diseño web y desarrollo en internet online

Problema con boton activado

Citar            
MensajeEscrito el 17 Ago 2007 09:25 am
Hola a todos, estoy utilizando la libreria de http://hosted.zeh.com.br/mctween/ para hacer un efecto de boton activado, pero no funciona.la cuestion es que mi boton esta formado por una animacion, por eso, el boton en reposo deberia esta en el frame 1 y si se hace rollover empezar la reproduccion del mismo.en su estado activado deberia estar en el ultimo frame de la animacion.mi codigo es este

Código :

#include "mc_tween2.as"
var myButtons = [this.b1, this.b2, this.b3, this.b4, this.b5];
var atras:Boolean = false;

for (var i=0; i<myButtons.length; i++) {
   atras = false;
}
   myButtons[i].onRollOver = function() {
      play();
   };
myButtons[i].onRollout = myButtons[i].onReleaseOutside = function() {
      atras = true;
   };
this.onEnterFrame = function():Void {
   if (atras) {
      prevFrame();
   }
}
myButtons[i].onRelease = function() {
      this._parent.activateItem (this);
}
this.activateItem = function(item) {
   // Function that activates a button.
   
   // Checks if there's an activated item already; if so, deactivates it.
   if (this.currentItem != false) this.deActivateItem();
   
   // Activates it, finally
   this.currentItem = item;
   this.currentItem.gotoAndPlay(2); // makes it 'disabled'
   this.currentItem.enabled = false; // makes it a disabled button, so it won't receive mouse events
};
      this.deActivateItem = function() {
   // Deactivates the current activated menu item.
   this.currentItem.enabled = true; // back to a normal button/movieclip
   this.currentItem.tween("_y", this.currentItem.prevFrame()); // back to its original position
   this.currentItem = undefined;
};

this.stop();
      

La verdad es que estoy un poco verde de as y no consigo hacer que funcione.
Si me podeis echar una mano os lo agradezco.
Gracias!

Por september

55 de clabLevel



 

firefox
Citar            
MensajeEscrito el 17 Ago 2007 01:11 pm
corrige el código como sigue:

Código :

#include "mc_tween2.as"
//*********************************************************************************************************
// este codigo debe ir primero que las funciones de cada botón, 
// para que el compilador los tenga definidos para cuando lo usas en la definición de los botones
//*********************************************************************************************************
this.activateItem = function(item) {
   // Function that activates a button.
   // Checks if there's an activated item already; if so, deactivates it.
   if (this.currentItem != false) this.deActivateItem(); // aqui desactiva el boton anteriormente oprimido
   // Activates it, finally
   this.currentItem = item; // aqui guarda el ultimo botón oprimido
   this.currentItem.gotoAndPlay(2); // makes it 'disabled'
   this.currentItem.enabled = false; // makes it a disabled button, so it won't receive mouse events
};
this.deActivateItem = function() {
     // Deactivates the current activated menu item.
     this.currentItem.enabled = true; // back to a normal button/movieclip
     this.currentItem.tween("_y", this.currentItem.prevFrame()); // back to its original position
     this.currentItem = undefined; 
};
this.stop();
//*********************************************************************************************************
// aqui se definen las funciones de tus botones (que deben ser movieclips)
//*********************************************************************************************************
var myButtons = [this.b1, this.b2, this.b3, this.b4, this.b5]; // estos deben ser movieclips, NO botones
var atras:Boolean = false; // esto no es necesario
for (var i=0; i<myButtons.length; i++) {
   myButtons[i].atras:Boolean  = false; // debes hacer referencia a una variable del botón.
// }   esta llave no va aqui, se comenta esta linea
   myButtons[i].onRollOver = function() {
      this.play(); 
   };
   myButtons[i].onRollout = myButtons[i].onReleaseOutside = function() {
      this.atras = true; // hacer referencia a una variable del boton
   };
   myButtons[i].onEnterFrame = function():Void { 
       // esta funcion se define para cada botón
      if (this.atras) { // hacer rreferencia a una variable del boton
        this.prevFrame();
      }
   }
   myButtons[i].onRelease = function() {
      this._parent.activateItem (this);
   }
} // aqui se cierra la llave 

espero que te funcione, y nos cuentas

Por gabynufe

Claber

446 de clabLevel



 

México, D.F.

msie7
Citar            
MensajeEscrito el 20 Ago 2007 07:55 am
Hola gabynufe, he intentado con el codigo que pones, y no funciona. Los botones cargan las secciones pero no se quedan marcados y no realizan la animacion al hacer onrollover.los botones tienen un stop en el frame 1 y en el ultimo por si te sirve de algo.
creo que this.currentItem.gotoAndPlay(2); // makes it 'disabled' esta mal ya que eso es lo que debe hacer al hacer rollover.

Como sera entonces?

Por september

55 de clabLevel



 

firefox
Citar            
MensajeEscrito el 20 Ago 2007 01:05 pm

Código :

#include "mc_tween2.as"
//*********************************************************************************************************
// este codigo debe ir primero que las funciones de cada botón, 
// para que el compilador los tenga definidos para cuando lo usas en la definición de los botones
//*********************************************************************************************************
this.activateItem = function(item) {
   // función que activa el botón.
   // Verifica si hay otro boton activado anteriormente, si es así entonces lo desactiva
   if (this.currentItem != false) this.deActivateItem(); // aqui desactiva el boton anteriormente presionado
   // Activa finalmente el boton presionado
   this.currentItem = item;  // aqui guarda el ultimo botón presionado
   this.currentItem.gotoAndStop(this.currentItem._totalframes); // se detiene en el ultimo frame de la animación
   this.currentItem.enabled = false; // deshabilita el boton, así no responde a los eventos del mouse
};
this.deActivateItem = function() {
     // desactiva el ultimo boton activado
     this.currentItem.enabled = true; // vuelve a responder a los eventos del mouse
     // se elimina el efecto tween, por ya estar implementado
     this.currentItem.atras = true; // prende el switch para iniciar animación alreves
     this.currentItem = undefined;
};
this.stop();
//*********************************************************************************************************
// aqui se definen las funciones de tus botones (que deben ser movieclips)
//*********************************************************************************************************
var myButtons = [this.b1, this.b2, this.b3, this.b4, this.b5]; // estos deben ser movieclips, NO botones
var atras:Boolean = false; // esto no es necesario
for (var i=0; i<myButtons.length; i++) {
   myButtons[i].atras:Boolean  = false; // debes hacer referencia a una variable del botón.
   myButtons[i].onRollOver = function() {
      this.gotoAndPlay(2);
    };
   myButtons[i].onRollout = myButtons[i].onReleaseOutside = function() {
      this.atras = true; // prende switch para iniciar animación alreves
   };
   myButtons[i].onEnterFrame = function():Void {
     // esta funcion se define para cada botón
      if (this.atras) { // hacer rreferencia a una variable del boton
        this.prevFrame();
        if (this._currentframe == 1) this.atras = false; // termina animación alreves
      }
   }
   myButtons[i].onRelease = function() {
      this._parent.activateItem (this);
   }
} // aqui se cierra la llave 

Con este codigo estoy suponiendo que:
--> el estado en reposo es el frame uno de cada boton
--> el estado RollOver, inicia la animación en el frame 2 hasta el frame final de cada boton
--> el estado RollOut, inicia la animación en reversa desde el ultimo frame, hasta el primero, para dejarlo en reposo
--> el estado activo es el ultimo frame de cada boton.

si no es esto lo que quieres, entonces explica cada estado de tu boton.

Por gabynufe

Claber

446 de clabLevel



 

México, D.F.

msie7
Citar            
MensajeEscrito el 21 Ago 2007 08:37 am
Exacto eso es lo que quiero, muchas gracias, ya funciona pero lo unico que no vuelve atrás al hacer rollout o sea que si pasas por el boton se queda en el ultimo frame de la animacion.
puede ser por tener dentro del movieclip del boton un stop(); en el primer y ultimo frame?[/code]

Por september

55 de clabLevel



 

firefox
Citar            
MensajeEscrito el 21 Ago 2007 12:45 pm
cambia la línea:
this.prevFrame();
por:

Código :

Foto = this._currentframe - 1;
this.gotoAndStop(Foto);

Por gabynufe

Claber

446 de clabLevel



 

México, D.F.

msie7

 

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