8 Replies Latest reply on Jan 7, 2010 8:28 AM by kglad

    thumbnail->large img reference in loop

    NeronBurningRome

      Hi,

      I got this code displaying thumbnails, made with a help of Ned Murphy a while ago. I need to display full image after releasing a thumbnail. I don't know how to create references to function displaying a proper full image, tracing 'i' returns the final 'i' value, that is '5'. And I need to load full image with the same number as thumbnail's instance name. Any ideas?

       

      var loader = new MovieClipLoader();
      var preloader = new Object();
      loader.addListener(preloader);

      i = 1;
      loadFunction();

       

      function loadFunction() {
          thumb_mc = this.createEmptyMovieClip(i, this.getNextHighestDepth());
          loader.loadClip("thumb"+i+".jpg", thumb_mc);
          preloader.onLoadInit = function() {
              loadCompleteFunction();       
          };  

      }

       

      function loadCompleteFunction() {

          this[i].onRelease = function () {
              callFullImage();
          }  


          i++;
          if (i<5) {
              loadFunction();
          }
      }

       

      function callFullImage() {

      trace(i);
      }

        • 1. Re: thumbnail->large img reference in loop
          kglad Adobe Community Professional & MVP

           

          var loader = new MovieClipLoader();
          var preloader = new Object();
          loader.addListener(preloader);

          preloader.onLoadInit = function() {
                 i++;
              if (i<5) {
                  loadFunction();
              } else {
          // start app.  loading complete.
          }
              };  

           

          i = 1;
          loadFunction();

           

          function loadFunction() {
              thumb_mc = this.createEmptyMovieClip("mc"+i, this.getNextHighestDepth());

          thumb_mc.createEmptyMovieClip("targetMC",1);

          thumb_mc.ivar=i;

          thumb_mc.onRelease=function(){

          trace(this.ivar);

          }

              loader.loadClip("thumb"+i+".jpg", thumb_mc.targetMC);

          }

           

          • 2. Re: thumbnail->large img reference in loop
            NeronBurningRome Level 1

            Thanx,

            You've changed almost everything and I was confussed for a while, but  now it works.

             

            I don't know how You guys do it - answering every question in like 10 minutes:)

             

            I'm still confused about few things:
            1. What does 'ivar' do? I couldn't find it in flash help nor in google.

            2. Is there any particular reason why it was necessary to create another empty MC ('targerMC') inside thumbs_mc? And why was targetMC's depth significant? And I know it was, coz' I changed it for a while and it didn't worked as it should.

            • 3. Re: thumbnail->large img reference in loop
              kglad Adobe Community Professional & MVP

              thumb_mc needs some way to know it's related to the number i.  assigning a property (i used ivar) to store that value allows thumb_mc to retrieve that value of i at any time.

               

              targetMC is needed because if you load into thumb_mc, all code assigned to thumb_mc (like ivar and that onRelease handler) will be reset to default when loading is started.

               

              actually, it doesn't matter what (non-negative) value you use for the depth of targetMC.  because thumb_mc has no other children, targetMC's depth can be anything.

              1 person found this helpful
              • 4. Re: thumbnail->large img reference in loop
                NeronBurningRome Level 1

                Thank you for explanation.

                I would have another question though.

                I have set of thumbnails in a row, one next to each other, each of them have different width, and I would like to set the x position of a thumbnail dynamically, depending on sum of width of previous thumbs. E.g. thumb3._x = thumb1._width + thumb2._width.

                Is it possible to implement such a solution in the code You wrote above?

                Maybe it will be easier to set identical width of every thumbnail - then setting the x value is much easier.

                • 5. Re: thumbnail->large img reference in loop
                  NeronBurningRome Level 1

                  Okey, I think I got it:

                   

                  I've put it into onLoadInit and it seems to work:

                   

                  for(j=1;j<i;j++) {
                          k="thmb"+j;
                          k=eval(k);
                          thumb_mc._x = thumb_mc._x + k._width +10;
                      }

                  • 6. Re: thumbnail->large img reference in loop
                    kglad Adobe Community Professional & MVP

                    it doesn't look like your code will work.

                     

                    use:

                     

                     

                     

                    var tl:MovieClip = this;

                     

                    var loader = new MovieClipLoader();
                    var preloader = new Object();
                    loader.addListener(preloader);

                    preloader.onLoadInit = function() {
                    if(i>1){
                    tl["mc"+i]._x = tl["mc"+(i-1)]._x+tl["mc"+(i-1)]._width+gapX;  // define gapX
                    } else {
                    tl.mc1._x = initialX;  // define intialX;
                    }
                       
                       i++;
                        if (i<5) {
                            loadFunction();
                        } else {
                    // start app.  loading complete.
                    }
                        };  

                     


                    i = 1;
                    loadFunction();


                     


                    function loadFunction() {
                        thumb_mc = this.createEmptyMovieClip("mc"+i, this.getNextHighestDepth());


                    thumb_mc.createEmptyMovieClip("targetMC",1);


                    thumb_mc.ivar=i;


                    thumb_mc.onRelease=function(){


                    trace(this.ivar);


                    }


                        loader.loadClip("thumb"+i+".jpg", thumb_mc.targetMC);


                    }


                     


                    1 person found this helpful
                    • 7. Re: thumbnail->large img reference in loop
                      NeronBurningRome Level 1

                      My proposition works as well, so I will be stubborn and use my own code:)

                      You're code would be helpfull coz it allows to define initial x value for 1.thumb, but I've done it other way.

                      Thanks anyway.