PDA

View Full Version : issue with alteration of Scotty's image resize....



ThePuzzleMaster
March 1st, 2006, 02:46 AM
I have a loop that dynamically loads thumbnails into a movie clip. As each thumb is loaded, it calls on a preloader function. This works for all the thumbs except the first one! No matter which one is the first one, it won't work on the first thumb.

The code is as follows:



function makeButtons() {
tnNr = 0;
clearInterval(delay);
for (var i = 0; i<tArray.length; i++) {
var thb = main_thumbs_mc.thumbClip.duplicateMovieClip("thmb"+i, 1000+i);
thb.id = i;
thb._x = 10+(i%5*118);
thb._y = 20+(Math.floor(i/5)*137);
}
loadButtons();
}
function loadButtons() {
var tbox = main_thumbs_mc["thmb"+tnNr].thumbEmpty;
trace(tbox);
tbox.loadMovie(tArray[tnNr]);
tbox._parent.preLoader();
temp = this.createEmptyMovieClip("tmp"+tnNr, 999);
temp.onEnterFrame = function() {
bt = tbox.getBytesTotal();
bl = tbox.getBytesLoaded();
if (bt == bl && bt>4) {
tbox._x += (tbox._parent._width-tbox._width)/2;
tbox._y += (tbox._parent._height-tbox._height)/2;
nextButton();
delete this.onEnterFrame;
}
};
}



the part that
says "tbox._parent.preLoader" is where the preloader is called, and I placed a trace() command in the preloader and it traces on every thumb except the first one. I thought maybe it was because it had an instance of 0, so I assigned tnNr a value of 1 and I also tried 5. And same thing. The first thumb (In this case, the second one or 6th one) did not load the preloader.

IS there something wrong with the code? Anyone have any ideas why this might be?

thanks a bunch.

scotty
March 1st, 2006, 03:33 AM
What's the code in your preloader() function?
And is this

tbox._parent.preLoader();
correct??
Why not have the preloader code in the loadButtons function?

scotty(-:

ThePuzzleMaster
March 1st, 2006, 03:41 AM
Here's my .fla

YEah, sorry that is indeed

tbox._parent.preLoader();




The preLoader() function works perfectly for every other thumbnail... Just not that first one.

Just forgot the ()'s when I typed it out down there.

Mostly, it's noticeable because the preLoader contains a resize function for the border. I gave it a separate layer so I don't have all my AS on one layer. I have a lot of code, so it gets kind of crowded.

Thanks for taking a look.
(And for the original file too! That's a great gallery!)

ThePuzzleMaster
March 1st, 2006, 03:52 AM
It's uploaded to www.mentalfabrications.com/test if you click on the "art" link, you can see the thumbs all resize except the first one.

Also, supporting files you may need would be uploaded there too.

scotty
March 1st, 2006, 04:58 AM
try it this way

var root = this;
function makeButtons() {
tnNr = 0;
clearInterval(delay);
for (var i = 0; i<tArray.length; i++) {
var thb = main_thumbs_mc.thumbClip.duplicateMovieClip("thmb"+i, 1000+i);
thb.id = i;
thb._x = 10+(i%5*118);
thb._y = 20+(Math.floor(i/5)*137);
}
delay = setInterval(root, "loadButtons", 100);
}
function loadButtons() {
clearInterval(delay);
var tbox = main_thumbs_mc["thmb"+tnNr].thumbEmpty;
tbox.loadMovie(tArray[tnNr]);
tbox._parent.preLoader();
temp = this.createEmptyMovieClip("tmp"+tnNr, 999);
temp.onEnterFrame = function() {
bt = tbox.getBytesTotal();
bl = tbox.getBytesLoaded();
if (bt == bl && bt>4) {
tbox._x += (tbox._parent._width-tbox._width)/2;
tbox._y += (tbox._parent._height-tbox._height)/2;
nextButton();
delete this.onEnterFrame;
}
};
}
for some reason you have to wait a little before the thumbs are defined

scotty(-:

ThePuzzleMaster
March 1st, 2006, 05:16 AM
Sweet! That worked marvelously!

Quick question.

How come the previous setInterval() in the galleryChoice() function doesn't require the "this" scope definition while that one in the makeButtons() function does?



function galleryChoice(q) {
trace(curLength);
pArray = new Array();
tArray = new Array();
iArray = new Array();
my_xml = new XML();
for (var j = 0; j<curLength; j++) {
main_thumbs_mc["thmb"+j].removeMovieClip();
}
my_xml.ignoreWhite = true;
my_xml.onLoad = function(loaded) {
if (loaded) {
gallery = this.firstChild.childNodes[q];
curLength = gallery.childNodes.length;
for (var i = 0; i<gallery.childNodes.length; i++) {
pArray.push(gallery.childNodes[i].attributes.source);
tArray.push(gallery.childNodes[i].attributes.thumb);
iArray.push(gallery.childNodes[i].attributes.title);
}
}
delay = setInterval(makeButtons, 50);
};
my_xml.load("art.xml");
}
var root=this
function makeButtons() {
tnNr = 0;
clearInterval(delay);
for (var i = 0; i<tArray.length; i++) {
var thb = main_thumbs_mc.thumbClip.duplicateMovieClip("thmb"+i, 1000+i);
thb.id = i;
thb._x = 10+(i%5*118);
thb._y = 20+(Math.floor(i/5)*137);
}
delay=setInterval(root,"loadButtons",100);
}
function loadButtons() {
clearInterval(delay)
var tbox = main_thumbs_mc["thmb"+tnNr].thumbEmpty;
trace(tbox);
tbox.loadMovie(tArray[tnNr]);
tbox._parent.preLoader();
temp = this.createEmptyMovieClip("tmp"+tnNr, 999);
temp.onEnterFrame = function() {
bt = tbox.getBytesTotal();
bl = tbox.getBytesLoaded();
if (bt == bl && bt>4) {
tbox._x += (tbox._parent._width-tbox._width)/2;
tbox._y += (tbox._parent._height-tbox._height)/2;
nextButton();
delete this.onEnterFrame;
}
};
}


thanks again!

ThePuzzleMaster
March 2nd, 2006, 06:06 PM
Anyone have an answer to the "Scope" question?

thanks

scotty
March 2nd, 2006, 07:04 PM
Not 100% sure, but I think because in makeButtons function 'this' is used.

scotty(-: