Comunidad de diseño web y desarrollo en internet online

Un listener y una función para varios botones.

Citar            
MensajeEscrito el 03 Jul 2011 08:52 am
Hola que tal, espero puedan ayudarme.

Tengo en mi stage un MovieClip llamado "container_mc", dentro del cual existen 5 MovieClips que actúan como botones, con el siguiente código se ejecutan todas las animaciones al mismo tiempo:

Código ActionScript :

import flash.display.MovieClip;

for (var i:Number=0; i<botonera_mc.numChildren; i++){
   botonera_mc.getChildAt(i).addEventListener(MouseEvent.ROLL_OVER, m_over)
   botonera_mc.getChildAt(i).addEventListener(MouseEvent.ROLL_OUT, m_out);
   botonera_mc.getChildAt(i).addEventListener(Event.ENTER_FRAME, mov);
   MovieClip(botonera_mc.getChildAt(i)).buttonMode = true;
}
   
var over:Boolean;

function m_over(event:MouseEvent):void
{
   over = true;
}

function m_out(event:MouseEvent):void
{
   over = false;
}

function mov(event:Event):void {
      if(over){
      event.target.nextFrame();
      }else{
      event.target.prevFrame();   
      }   
}



Lo que quiero es que con un "listener" y una "función" pueda ejecutar solo la animación del botón(MovieClip) al que hago "ROLL_OVER/ROLL_OUT" y no se animen todos los botones al mismo tiempo.

De antemano les agradesco su ayuda.

Por e619

1 de clabLevel



 

Diseñador Gráfico Freelance

chrome
Citar            
MensajeEscrito el 04 Jul 2011 01:57 pm
Dices que se llama container_mc, pero en el for usas botonera_mc.numChildren ...

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 04 Jul 2011 08:20 pm
Cierto, en mi .fla el código está bien, no tengo errores. No me di cuenta al crear el post que lo había escrito mal, gracias Jorge, sin embargo el problema sigue igual.

Oops no encuentro en dónde editar el post/tema para corregir ese error, quizá tenga que crear un nuevo post.

Por e619

1 de clabLevel



 

Diseñador Gráfico Freelance

chrome
Citar            
MensajeEscrito el 04 Jul 2011 08:48 pm
Prueba algo asï

Código ActionScript :

var over:Boolean; 
var who:MovieClip

function m_over(event:MouseEvent):void 
{ 
   over = true; 
   who = event.target as MovieClip
  try{
         removeEventListener(Event.ENTER_FRAME, mov);  
   } catch(e:Error){}
   addEventListener(Event.ENTER_FRAME, mov); 
} 
 
function m_out(event:MouseEvent):void 
{ 
   over = false; 
} 
 
function mov(event:Event):void { 
      if(over){ 
        who.nextFrame(); 
      }else{ 
        who.prevFrame(); 
        if(who.currentFrame==1) removeEventListener(Event.ENTER_FRAME, mov);  
      }    
} 


Igual descubrirás un nuevo problema: si pasas rápido los botones se quedan a la mitad

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 05 Jul 2011 03:38 am
Gracias solisarg, lo he intentado así pero ahora ya nofunciona el ROLL_OVER ni ROLL_OUT, la animación de los botones se dispara sola.

Seguiré modificando un poco el código.

Por e619

1 de clabLevel



 

Diseñador Gráfico Freelance

chrome

 

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