Movieclips hacer clic en la generación de problemas de ActionScript

  • vinid3
  • Novice
  • Novice
  • No Avatar
  • Registrado: Sep 17, 2009
  • Mensajes: 17
  • Status: Offline

Nota Septiembre 17th, 2009, 1:57 pm

¡Hola a todos! Este es mi primer post aquí, he oído esta placa estaba lleno de ventajas de ActionScript, así que decidí ponerme en contacto con su comunidad, Im no como una tabla-fanático, pero tal vez podría convertirse en una rápida :wink:

Este es mi problema ActionScript (AS2)
El objetivo de este script, si es para cargar imágenes desde un xml, mostrarlas en Screan, y al hacer clic en uno de ellos, muestran la grande. Sé que hay un montón de guiones ya hechos, pero como me gustaría aprender, trato de hacerlo yo mismo....

Ahora el problema es en realidad el onRelease...En este ejemplo, cualquiera que sea la imagen que presione, siempre me: "click en la imagen: 5" como salida .. (cuando se cargan 5 imágenes...)

¿Alguien tiene idea?

Supongo que hay un montón de errores y tal vez mejores formas de hacer en este guión, pero como he dicho, soy un novato, así que no dudes en decírmelo!

¡Muchas gracias!!

Vincent (de habla francesa)


Código: [ Select ]
//////////////////////////
//PARAMETERS
//////////////////////////
espacement = 10;//l'espacement en px entre les images
displayinterval = 200;//interval de chargement des images en ms
xmlfile = "test.xml";//fichier xml a utiliser (peut etre variable);




//////////////////////////
//LOADING IMAGES AND LINKING
//////////////////////////
Fichier_XML = new XML();
Fichier_XML.ignoreWhite = true;
Fichier_XML.load(xmlfile);
Fichier_XML.onLoad = function(Reussite)
{
    if (Reussite)
        {
            _root.x = Fichier_XML.childNodes[0];//Is the main Node: <main>
            for(i = 0; x.childNodes[i] != undefined; i++)
            {
                var mc = createEmptyMovieClip("picture"+i, i);
                mc.createEmptyMovieClip("thumb", 0);
                loadMovie(x.childNodes[i].childNodes[2].firstChild,mc.thumb); //the node here contains an jpg URL
                mc.onRelease = function ()
                {
                    trace("clicked on image: "+i);
                }
            }
            totalpictures = i;//to know how many images have been loaded...
    }
}



//////////////////////////
//POSITIONING
//////////////////////////
this.onEnterFrame = function()
{
    nombreparrangee = 3;
    for(i=0;i<totalpictures;i++)
    {
        //colonne de 0
        colonne = Math.ceil((i+1)/nombreparrangee)-1;
                
        //ligne (0,1,2) a partir de 0
        ligne = (i-(colonne*nombreparrangee));
                
        //le saut par bloc
        saut = picture0._width+espacement;    
        
        //Application des parametres
        this["picture"+i]._x -= (this["picture"+i]._x-(espacement + (colonne*saut)))/5;
        this["picture"+i]._y -= (this["picture"+i]._y-(espacement + (ligne*saut)))/5;
    }
}
        
  1. //////////////////////////
  2. //PARAMETERS
  3. //////////////////////////
  4. espacement = 10;//l'espacement en px entre les images
  5. displayinterval = 200;//interval de chargement des images en ms
  6. xmlfile = "test.xml";//fichier xml a utiliser (peut etre variable);
  7. //////////////////////////
  8. //LOADING IMAGES AND LINKING
  9. //////////////////////////
  10. Fichier_XML = new XML();
  11. Fichier_XML.ignoreWhite = true;
  12. Fichier_XML.load(xmlfile);
  13. Fichier_XML.onLoad = function(Reussite)
  14. {
  15.     if (Reussite)
  16.         {
  17.             _root.x = Fichier_XML.childNodes[0];//Is the main Node: <main>
  18.             for(i = 0; x.childNodes[i] != undefined; i++)
  19.             {
  20.                 var mc = createEmptyMovieClip("picture"+i, i);
  21.                 mc.createEmptyMovieClip("thumb", 0);
  22.                 loadMovie(x.childNodes[i].childNodes[2].firstChild,mc.thumb); //the node here contains an jpg URL
  23.                 mc.onRelease = function ()
  24.                 {
  25.                     trace("clicked on image: "+i);
  26.                 }
  27.             }
  28.             totalpictures = i;//to know how many images have been loaded...
  29.     }
  30. }
  31. //////////////////////////
  32. //POSITIONING
  33. //////////////////////////
  34. this.onEnterFrame = function()
  35. {
  36.     nombreparrangee = 3;
  37.     for(i=0;i<totalpictures;i++)
  38.     {
  39.         //colonne de 0
  40.         colonne = Math.ceil((i+1)/nombreparrangee)-1;
  41.                 
  42.         //ligne (0,1,2) a partir de 0
  43.         ligne = (i-(colonne*nombreparrangee));
  44.                 
  45.         //le saut par bloc
  46.         saut = picture0._width+espacement;    
  47.         
  48.         //Application des parametres
  49.         this["picture"+i]._x -= (this["picture"+i]._x-(espacement + (colonne*saut)))/5;
  50.         this["picture"+i]._y -= (this["picture"+i]._y-(espacement + (ligne*saut)))/5;
  51.     }
  52. }
  53.         
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Septiembre 17th, 2009, 1:57 pm

  • vinid3
  • Novice
  • Novice
  • No Avatar
  • Registrado: Sep 17, 2009
  • Mensajes: 17
  • Status: Offline

Nota Septiembre 18th, 2009, 12:19 am

lo tengo trabajo! :D Esta es la respuesta:

Código: [ Select ]
if (Reussite)
        {
            _root.x = Fichier_XML.childNodes[0];//Is the main Node: <main>
            for(i = 0; x.childNodes[i] != undefined; i++)
            {
                
                mc = createEmptyMovieClip("picture"+i, i);
                mc.createEmptyMovieClip("thumb", 0);
                loadMovie(x.childNodes[i].childNodes[2].firstChild,mc.thumb); //the node here contains an jpg URL
                mc.indice = i;
                mc.onRelease = function()
                {
                    trace(this.indice);
                }
            }
            totalpictures = i;//to know how many images have been loaded...
    }
  1. if (Reussite)
  2.         {
  3.             _root.x = Fichier_XML.childNodes[0];//Is the main Node: <main>
  4.             for(i = 0; x.childNodes[i] != undefined; i++)
  5.             {
  6.                 
  7.                 mc = createEmptyMovieClip("picture"+i, i);
  8.                 mc.createEmptyMovieClip("thumb", 0);
  9.                 loadMovie(x.childNodes[i].childNodes[2].firstChild,mc.thumb); //the node here contains an jpg URL
  10.                 mc.indice = i;
  11.                 mc.onRelease = function()
  12.                 {
  13.                     trace(this.indice);
  14.                 }
  15.             }
  16.             totalpictures = i;//to know how many images have been loaded...
  17.     }
  • graphixboy
  • Control + Z
  • Mastermind
  • Avatar de Usuario
  • Registrado: Jul 11, 2005
  • Mensajes: 1828
  • Loc: In the Great White North
  • Status: Offline

Nota Septiembre 18th, 2009, 7:56 am

Eso es lo que yo habría recomendado. ¿Entiendes lo que pasó?
If at first you don't succeed F1... If that doesn't work try Google!
//// Designer, Developer & Teacher - Interactive, Motion and 3D \\\\
Portfolio at WhenImNotSleeping.com
  • vinid3
  • Novice
  • Novice
  • No Avatar
  • Registrado: Sep 17, 2009
  • Mensajes: 17
  • Status: Offline

Nota Septiembre 18th, 2009, 8:05 am

Sí, lo sé, al menos en mi opinión, la función sólo es llamado cuando se presione el clip de película, y en ese momento, bueno, vale la pena el valor final, mucho después de que Flash se ha terminado con el "para"


¿Tengo razón?

Ive consiguió otra pregunta, no la problemática, pero de todos modos:
¿Cómo podría transformar este, para tener una imagen que aparece, digamos, cada 200 ms? No puedo ver una forma de utilizar setInterval aquí....

¿Tienes una idea?

Gracias!
  • IceCold
  • Guru
  • Guru
  • Avatar de Usuario
  • Registrado: Nov 05, 2004
  • Mensajes: 1254
  • Loc: Ro
  • Status: Offline

Nota Septiembre 19th, 2009, 1:42 am

Código: [ Select ]
// first hide all pictures:
for(var pIndex = 0; pIndex < totalpictures; pIndex++)
{
  this["picture" + pIndex]._visible = false;  
}

var pictureIndex = 0; // starting picture index
var intervalID = setInterval(ShowPicture, 200);
function ShowPicture()
{
  this["picture" + pictureIndex]._visible = true;
  pictureIndex++; // set next picture index
  if (pictureIndex >= totalpictures)
    pictureIndex = 0; // start again from 0
}
  1. // first hide all pictures:
  2. for(var pIndex = 0; pIndex < totalpictures; pIndex++)
  3. {
  4.   this["picture" + pIndex]._visible = false;  
  5. }
  6. var pictureIndex = 0; // starting picture index
  7. var intervalID = setInterval(ShowPicture, 200);
  8. function ShowPicture()
  9. {
  10.   this["picture" + pictureIndex]._visible = true;
  11.   pictureIndex++; // set next picture index
  12.   if (pictureIndex >= totalpictures)
  13.     pictureIndex = 0; // start again from 0
  14. }
“True mastery transcede any particular art. It stems from mastery of oneself - the ability, developed throgh self-discipline, to be calm, fully aware, and complety in tune with oneself and the surroundings. Then, and only then, can a person know himself. ”
  • vinid3
  • Novice
  • Novice
  • No Avatar
  • Registrado: Sep 17, 2009
  • Mensajes: 17
  • Status: Offline

Nota Septiembre 19th, 2009, 1:57 am

Cool, gracias por el código, suena lógico!
Pero todavía hay un problema con mi código principal, tengo la sensación de que no puede llamar a mi movieclipinstance...

cuando ésta:
_root.picture1._visible = false;
codificados, así, Picture1 es aún visible gif "alt =":(" title =" triste ">

aunque, cuando lo puse en un onEnterFrame, y luego desaparece, así que supongo que esto debe ser debido al hecho de que este comando vibility se establece antes de la acción de loadMovie, y como la acción loadMovie borra todas las propiedades de clip de película...aparece de nuevo (creo)
  • IceCold
  • Guru
  • Guru
  • Avatar de Usuario
  • Registrado: Nov 05, 2004
  • Mensajes: 1254
  • Loc: Ro
  • Status: Offline

Nota Septiembre 19th, 2009, 4:20 am

Es extraño, porque no se carga la imagen dentro de _root.picture1
crear un pulgar y luego cargar la imagen en que movieclip pulgar, por lo único que recibe todas sus propiedades reseted.

Yo solía cargar las imágenes en AS2, pero se me olvidó si el archivo. _visible Propiedad en el conjunto no pare realmente funciona. En cualquier caso, el archivo. _alpha = 0 funciona con seguridad, lo que puede establecer en un principio, y después de todas las películas se cargan puede establecer la _visible = false y. _alpha A 100.
Usted puede agregar una prueba bastante fácil en onEnterFrame para comprobar si se cargan todos ellos.
Código: [ Select ]
function TestLoaded()
{
  var picturesLoaded = 0;
  for(var pIndex = 0; pIndex < totalpictures; pIndex++)
  {
   crtPicture = this["picture" + pIndex];
   if (crtPicture.bytestotal > 0)
   {
     if (crtPicture.bytesloaded >= crtPicture.bytestotal)
       picturesLoaded++;
   }
  }
  if (picturesLoaded == totalpictures)
   return true;
  else
   return false;
}
  1. function TestLoaded()
  2. {
  3.   var picturesLoaded = 0;
  4.   for(var pIndex = 0; pIndex < totalpictures; pIndex++)
  5.   {
  6.    crtPicture = this["picture" + pIndex];
  7.    if (crtPicture.bytestotal > 0)
  8.    {
  9.      if (crtPicture.bytesloaded >= crtPicture.bytestotal)
  10.        picturesLoaded++;
  11.    }
  12.   }
  13.   if (picturesLoaded == totalpictures)
  14.    return true;
  15.   else
  16.    return false;
  17. }

Esto le dirá cuando todas las fotos que se han cargado, y la adición de esta prueba en onEnterFrame, después de que se devuelve true, puede comenzar a ocultar las imágenes y establecer alfa a 100
“True mastery transcede any particular art. It stems from mastery of oneself - the ability, developed throgh self-discipline, to be calm, fully aware, and complety in tune with oneself and the surroundings. Then, and only then, can a person know himself. ”
  • vinid3
  • Novice
  • Novice
  • No Avatar
  • Registrado: Sep 17, 2009
  • Mensajes: 17
  • Status: Offline

Nota Septiembre 21st, 2009, 4:00 am

Gracias por todas las respuestas!

Publicar Información

  • Total de mensajes en este tema: 8 mensajes
  • Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 35 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC