Comunidad de diseño web y desarrollo en internet online

Eventos en un clip generado por actionscript

Citar            
MensajeEscrito el 24 Oct 2007 01:47 pm
Hola, estoy haciendo una galería de imágenes, y al generar los thumbnails los eventos onRelease, onRollOver... no me funcionan. Podría alguien decirme cual es mi error?

Código :

function generate_thumbs() {
   var container:MovieClip = this.createEmptyMovieClip("container",this.getNextHighestDepth());
   for(i = 0; i< total;i++) {
      thumb:MovieClip = container.createEmptyMovieClip("thumb"+i,i);
      thumb.loadMovie(thumbnail[i], 1);
      thumb._xscale = thumb._yscale = 90;
      thumb._x = (i)* 40;
      thumb.onRollOver = function () {thumb._xscale = thumb._yscale = 100;};
      thumb.onRollOut = function () { thumb._xscale = thumb._yscale = 90;};
      thumb.onRelease = function() {
         nImage(i);
      }
   }
   container._x = 60;
   container._y = (this._height - 30);


Me muestra las imágenes correctamente, pero no ocurren los eventos que le puse. Que debería hacer?

También tengo otras preguntas
- Después de meter la imagen al MovieClip el ancho (thumb._width) me sigue dando 0. Igual para el container, tras añadir todos los thumbnails su width es 0. Cómo puedo saber el ancho correcto del MovieClip?

Está bien meter la función nImage(i) así?. Digo, al final del bucle i va a ser igual a total. Al hacer click se va a ejecutar la función con el valor que tuvo i en ese momento o el valor final de i?

Espero me puedan ayudar. Gracias por todo.


Ahh por cierto estoy usando el flash MX (no el 2004 MX)..

Por charlieman

2 de clabLevel



Genero:Masculino  

mozilla
Citar            
MensajeEscrito el 24 Oct 2007 01:50 pm
Ups, donde puse:

Código :

thumb:MovieClip = container.createEmptyMovieClip("thumb"+i,i);


era

Código :

thumb = container.createEmptyMovieClip("thumb"+i,i);


:oops:

Por charlieman

2 de clabLevel



Genero:Masculino  

mozilla
Citar            
MensajeEscrito el 24 Oct 2007 05:27 pm
Vamos a ver:

  1. Puedes colocar el "thumb:MovieClip" si colocar antes la palabra clave "var", para declarar la variable e identificar su tipo. De hecho, es lo recomendado.

    Código :

    var thumb:MovieClip = container.createEmptyMovieClip("thumb"+i,i);
    

  2. Los eventos no funcionan porque la variable "thumb" sólo existe dentro del for, luego es "undefined" (Busca en la Ayuda de Flash sobre "Ámbito de Variables"). Simplemente cambia "thumb" por "this".

    Código :

    thumb.onRollOver = function () {this._xscale = this._yscale = 100;};
    thumb.onRollOut = function () { this._xscale = this._yscale = 90;};
    

  3. Para resolver el asunto de nImage. Crea una propiedad (llamada por ejemplo "id" a cada thumb para que haga referencia a la imagen que necesitas.

    Código :

    thumb.id = i;
    thumb.onRollOver...
    thumb.onRelease = function(){nImage(this.id)};
    

Por The Fricky!

Presidente

6168 de clabLevel

3 tutoriales
8 articulos

Genero:Masculino   Bastard Operators From Hell Héroes

Piccola Venezia...

firefox
Citar            
MensajeEscrito el 25 Oct 2007 10:43 pm
Hola The Friky!, gracias por la responder.

Intente eso, pero aún así los eventos no responden.

También he intentado utilizar addEventListener:

Código :

thumb.addEventListener("click", function(){ nImage(this.id)} );


Pero tampoco funciona. Es que onRelease no funciona en los MovieClips?

Por charlieman

2 de clabLevel



Genero:Masculino  

mozilla
Citar            
MensajeEscrito el 25 Oct 2007 10:52 pm
onRelease funciona con los movieclips. Haz un trace a ver si el problema es con los onRelease o con la función nImage

Por The Fricky!

Presidente

6168 de clabLevel

3 tutoriales
8 articulos

Genero:Masculino   Bastard Operators From Hell Héroes

Piccola Venezia...

firefox

 

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