I have a gallery that reads an ms access database using asp and then loops through an array of records and duplicates an empty movieclip for each record.
A jpeg is then loaded into the movieclip and then a variable for the _x position is incremented and then the next one is loaded etc.
I then use the same method to add the necessary labels for the images by duplicating a movieclip and adding a text field.
This is all fine and produces a gallery of images but the problem comes when I try and position the labels according to the height of the image. I have tried every method I can think of to check the image attributes which are only available when it is fully loaded, but I keep getting a value of 0.
The code is below. Any help would be greatly appreciated - thanx
stop();
// Set variable holding image folder path
sThumbImageLoc = "thumbs/";
// Retrieve thumb ID's
//_root.artist_name = _root.varThumbs.artist_name;
_root.aID = _root.varThumbs.aID.split(",");
_root.aID_length = _root.aID.length;
// Retrieve Thumb titles
_root.aTitle = _root.varThumbs.aTitle.split(",");
// Retrieve Media types
_root.aMedia = _root.varThumbs.aMedia.split(",");
// Retrieve Frame Heights
_root.aFrameH = _root.varThumbs.aFrameH.split(",");
// Retrieve Frame Widths
_root.aFrameW = _root.varThumbs.aFrameW.split(",");
// Retrieve Image Heights
_root.aImgH = _root.varThumbs.aImgH.split(",");
// Retrieve Image Widths
_root.aImgW = _root.varThumbs.aImgW.split(",");
// Retrieve Prices
_root.aPrice = _root.varThumbs.aPrice.split(",");
// Display image
// This function retrieves and displays the main image on top when passed the image ID
function getmainImage(ImageID){
// load main image holder movie
_root.current_imageID = ImageID;
loadMovie("main_image.swf", "_root.drop_main");
};
maindepth = 9000;
textdepth = 8000;
thumbbtndepth = 6000;
thumbdepth = 5000;
labelsdepth = 4000;
thumbbgrddepth = 3000;
xthumbposition = 0;
//ytextposition = 338;
//
function searchAndReplace(holder, searchfor, replacement) {
temparray = holder.split(searchfor);
holder = temparray.join(replacement);
return (holder);
}
function whenloaded(mc_name, mc_height) {
// Determine size of image and resize window and position labels accordingly
ytextposition = mc_height + 10;
//_root.test = mc_height;
// vertical positions
setProperty(searchAndReplace(mc_name, "thumb", "media"), _y, ytextposition+51);
setProperty(searchAndReplace(mc_name, "thumb", "imageID"), _y, ytextposition+123);
setProperty(searchAndReplace(mc_name, "thumb", "title"), _y, ytextposition+33);
setProperty(searchAndReplace(mc_name, "thumb", "fsize"), _y, ytextposition+105);
setProperty(searchAndReplace(mc_name, "thumb", "isize"), _y, ytextposition+87);
setProperty(searchAndReplace(mc_name, "thumb", "price"), _y, ytextposition+69);
}
// Display thumbnails
for (a=0; a<_root.aID_length; a++){
// create new thumb movieclip
duplicateMovieClip(_root.drop_thumbs.drop_thumb, "thumb"+a, thumbdepth);
// create new thumb bgrd
duplicateMovieClip(_root.drop_thumbs.thumb_bgrd, "bgrd"+a, thumbbgrddepth);
// create new invisible thumb btn
duplicateMovieClip(_root.drop_thumbs.thumb_btn, _root.aID[a], thumbbtndepth);
// create new Media type text box
duplicateMovieClip(_root.drop_thumbs.text_box, "media"+a, textdepth);
// create new image ID text box
duplicateMovieClip(_root.drop_thumbs.text_box, "imageID"+a, textdepth+20);
// create new title text box
duplicateMovieClip(_root.drop_thumbs.text_box, "title"+a, textdepth+40);
// create new frame size text box
duplicateMovieClip(_root.drop_thumbs.text_box, "fsize"+a, textdepth+60);
// create new image size text box
duplicateMovieClip(_root.drop_thumbs.text_box, "isize"+a, textdepth+80);
// create new price text box
duplicateMovieClip(_root.drop_thumbs.text_box, "price"+a, textdepth+100);
// Store current thumb in variable
_root.current_thumb = "_root.drop_thumbs."+eval("thumb"+a);
// Load the thumbnail into the new target movie
loadMovie(sThumbImageLoc+_root.aID[a]+".jpg", _root.current_thumb);
// Check when image is loaded and position labels accordingly using function
eval("thumb"+a).isLoaded = false;
eval("thumb"+a).onEnterFrame = function() {
if (!this.isLoaded) {
if (Math.round(this.getBytesTotal()) == Math.round(this.getBytesLoaded())) {
this.isLoaded = true;
}
}
if (this.isLoaded) {
delete this.onEnterFrame;
//_root.test = this._height;
whenloaded(this._name, this._height);
}
}
// Set positions of movieclips
setProperty(eval("thumb"+a), _x, (xthumbposition+25));
setProperty(eval("bgrd"+a), _x, xthumbposition);
setProperty(_root.aID[a], _x, xthumbposition);
// horizontal positions
setProperty("media"+a, _x, xthumbposition+41);
setProperty("imageID"+a, _x, xthumbposition+74);
setProperty("title"+a, _x, xthumbposition+41);
setProperty("fsize"+a, _x, xthumbposition+74);
setProperty("isize"+a, _x, xthumbposition+74);
setProperty("price"+a, _x, xthumbposition+41);
// Add text fields and set formatting
eval("media"+a).createTextField("txt1", textdepth, 10, -15, 200, 20);
eval("media"+a).txt1.text = _root.aMedia[a];
eval("imageID"+a).createTextField("txt1", textdepth+20, 10, -15, 200, 20);
eval("imageID"+a).txt1.text = _root.aID[a];
eval("title"+a).createTextField("txt1", textdepth+40, 10, -15, 200, 20);
eval("title"+a).txt1.text = _root.aTitle[a];
eval("fsize"+a).createTextField("txt1", textdepth+60, 10, -15, 200, 20);
eval("fsize"+a).txt1.text = _root.aFrameH[a]+' by '+_root.aFrameW[a]+'cm';
eval("isize"+a).createTextField("txt1", textdepth+80, 10, -15, 200, 20);
eval("isize"+a).txt1.text = _root.aImgH[a]+' by '+_root.aImgW[a]+'cm';
eval("price"+a).createTextField("txt1", textdepth+100, 10, -15, 100, 20);
eval("price"+a).txt1.text = '
+_root.aPrice[a]+’ AUD’;
myTextFormat = new TextFormat();
myTextFormat.color = “0x074667”;
myTextFormat.font = “Arial”;
myTextFormat.size = 12;
myTextFormat.bold = true;
eval(“media”+a).txt1.setTextFormat(myTextFormat);
eval(“imageID”+a).txt1.setTextFormat(myTextFormat);
eval(“title”+a).txt1.setTextFormat(myTextFormat);
eval(“fsize”+a).txt1.setTextFormat(myTextFormat);
eval(“isize”+a).txt1.setTextFormat(myTextFormat);
eval(“price”+a).txt1.setTextFormat(myTextFormat);
// Define button handling events
eval(_root.aID[a]).onRelease = function(){
getMainImage(this._name);
}
thumbdepth–;
labelsdepth–;
thumbbgrddepth–;
thumbbtndepth–;
textdepth = textdepth + 120;
xthumbposition = xthumbposition + 250;
};