Flickr Gallery

I’ve recently been trying to adapt a Flash Flickr API gallery to suit my own needs but my code is not working as was intended.

I keep hitting a brick wall with the code - it is working to a degree but the calculations on how many thumbs to load into a ‘next’ set of pages isn’t working properly. The ‘next’ page is loading the container while taking one loaded photo away (in this example).

For example: i’ve set the below code to create 5 thumbs (column) by 2 rows (rows * columns = 10 thumbs per page). There are 12 images in total, which then creates a 2nd page. This is where the problem unfolds; when on the 2nd page, the 11th photo is being dynamically created but not the 12th…

If anyone can spot what i am doing wrong i would be very grateful…i’ve started to get coding blindness and knowing i’m just looking past the problem, i think a fresh set of eyes would be cool.

Stage.scaleMode = "noScale";
Stage.align = "TL";
Stage.showMenu = false;
showDebug = "false";
//
flickrKey = "";
userID = "";
//
page = 1;
numSqrsWidth = 5;
numSqrsHeight = 2;
columnGap = 10;
rowGap = 10;
//
loadingAnother = false;
firstGo = true;
my_flickr = new Flickr (flickrKey);
totalSqrs = numSqrsWidth * numSqrsHeight;
prevBtn._visible = false;
nextBtn._visible = false;
//
my_flickr.photos.onGetInfo = function (error, obj) {
    if (!error) {
        var my_dateTime:Array = _root.imageDate.split (" ");
        var my_dateSplit:Array = my_dateTime[0].split ("-");
        largeImage.imageName.text = largeImage.imageName.text + " - " + my_dateSplit[2] + "/" + my_dateSplit[1] + "/" + my_dateSplit[0];
        if (_root.descriptionText == undefined) {
            largeImage.imageDis.text = "";
        }
        else {
            largeImage.imageDis.text = _root.descriptionText;
        }
    }
    else {
        trace ("loading error");
    }
};
//
function getDescription (imageID) {
    my_flickr.photos.getInfo (imageID);
}
//
my_flickr.people.onPublicPhotos = function (error, obj) {
    if (!error) {
        readyToCreateGrid = true;
        createGrid ();
    }
    else {
        trace ("loading error");
    }
};
function createGrid () {
    if (firstGo) {
        _root.loading_mc.gotoAndStop ("off");
        //removeMovieClip(loading_mc);
        nextBtn._visible = true;
        firstGo = false;
        if (totalSqrs < _root.totalPhotos) {
            numberOfSqrsToMake = totalSqrs;
            totalPages = Math.ceil (_root.totalPhotos / totalSqrs);
            startNumber = (page - 1) * totalSqrs;// + 1;
        }
        else {
            numberOfSqrsToMake = _root.totalPhotos;
            totalPages = 1;
            startNumber = 1;
        }
    }
    else {
        startNumber = (page - 1) * totalSqrs + 1;
        if ((totalPhotos - startNumber) > totalSqrs) {
            numberOfSqrsToMake = totalSqrs;
            nextBtn._visible = true;
        }
        else {
            nextBtn._visible = false;
            numberOfSqrsToMake = totalPhotos - startNumber;
        }
    }
    if (page == 1) {
        prevBtn._visible = false;
        if (totalPages == 1) {
            nextBtn._visible = false;
        }
    }
    else {
        prevBtn._visible = true;
    }
    columnCounter = 2;
    rowCounter = 1;
    if (needDestoryOld and numberOfSqrsToMake < totalSqrs) {
        destoryOld (numberOfSqrsToMake);
    }
    //load data into square 1    
    if (numberOfSqrsToMake > 0) {
        pages.text = "page " + page + " of " + totalPages;
        loadMovie (_root["photoURL_s" + startNumber], gridItem1.holder.placeholder);
        gridItem1.myName = _root["photoName" + startNumber];
        gridItem1.myLargeUrl = _root["photoURL_l" + startNumber];
        gridItem1.myID = _root["photoID" + startNumber];
        gridItem1.myPlace = startNumber;
        //load data into other squares
        startMakingFrom = startNumber + 1;
        //
        for (var i = 2; i <= numberOfSqrsToMake; i++) {
            needDestoryOld = true;
            if (columnCounter > numSqrsWidth) {
                columnCounter = 1;
                rowCounter++;
            }
            duplicateMovieClip (gridItem1, "gridItem" + i, i);
            loadMovie (_root["photoURL_s" + startMakingFrom], this["gridItem" + i].holder.placeholder);
            this["gridItem" + i].myID = _root["photoID" + startMakingFrom];
            this["gridItem" + i].myName = _root["photoName" + startMakingFrom];
            //this["gridItem" + i].numText.text = i;
            this["gridItem" + i].myLargeUrl = _root["photoURL_l" + startMakingFrom];
            this["gridItem" + i].myPlace = startMakingFrom;
            this["gridItem" + i]._x = gridItem1._x + ((columnCounter - 1) * (gridItem1._width + columnGap));
            this["gridItem" + i]._y = gridItem1._y + ((rowCounter - 1) * (gridItem1._width + rowGap));
            columnCounter++;
            startMakingFrom++;
        }
        _root.largeImage.swapDepths (_root.getNextHighestDepth ());
        //_root.debug_mc.swapDepths (_root.getNextHighestDepth ());
    }
    else {
        gridItem1._visible = false;
        error.gotoAndPlay ("no images");
    }
    trace (totalPhotos);
}
function destoryOld () {
    //num++;
    //for (var i = num; i <= totalSqrs; i++) {
    //removeMovieClip (this["gridItem" + i]);
    //num = -1;
    for (var i = 1; i <= totalSqrs; i++) {
        this["gridItem" + i].removeMovieClip ();
    }
}
my_flickr.people.getPublicPhotos (_root.userID, 500, 1);

there isn’t much real code there

I can only assume you have for loop that is starting at 1 or finishing before it should