Skip to main content
January 6, 2010
Answered

thumbnail->large img reference in loop

  • January 6, 2010
  • 1 reply
  • 701 views

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.onRelease = function () {
        callFullImage();
    }  


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

function callFullImage() {

trace(i);
}

This topic has been closed for replies.
Correct answer kglad

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);

}

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
January 6, 2010

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);

}

January 7, 2010

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.

kglad
Community Expert
Community Expert
January 7, 2010

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.