Trying to resolve the issues with my previous post, I thought I would introduce a callback... ( I know it doesn't fix the problem but it might be an acceptable compromise)
So I have an object for holding file selected info
this is the displayBanner callback...
So when the file is selected I have the onload event run for the image and then fire my callback...
But the callback is running the millisecond a file is selected, which means it isn't firing from within the onload event of the image, but is firing when the function is being assigned to the onload event.
Why? How do you write code to execute a callback function from within a holding variable without the function firing just by mentioning the variable?
I thought this was to do with using parentheses, but there aren't any involved so it can't be?
Thanks,
1DMF
"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
So I have an object for holding file selected info
Code:
var fileObj = {
maxSize:1,
fileType:'img',
fileInvalid:'Only image files (GIF / PNG / JPG) allowed.',
imgWidth:200,
imgHeight:584,
callback:displayBanner
}; // file object settings
this is the displayBanner callback...
Code:
// display selected banner for upload
function displayBanner()
{
console.log(fileObj.file.src);
if(fileObj.file.src)
{
$('#right').html('<img src="', fileObj.file.src,'" title="',$('#tooltip').val(),'" />"');
}
}
So when the file is selected I have the onload event run for the image and then fire my callback...
Code:
// set up a fileReader object and image object
var reader = new FileReader();
fObj.file = new Image();
// load event to capture the file information.
reader.onload = (function(file) {
fObj.file.src = file.target.result;
// load event to check image dimensions
fObj.file.onload = function(){
if(this.width != fObj.imgWidth || this.height != fObj.imgHeight)
{
showDialog({content:'Image dimensions invalid. Must be (Width: ' + fObj.imgWidth + 'px, Height:' + fObj.imgHeight + 'px)'});
clearFile(ele);
fObj.file = undefined;
}
else
{
[b][u]try{fObj.callback}[/u][/b]
catch(e){}
}
};
});
// read selected file
reader.readAsDataURL(myFile);
But the callback is running the millisecond a file is selected, which means it isn't firing from within the onload event of the image, but is firing when the function is being assigned to the onload event.
Why? How do you write code to execute a callback function from within a holding variable without the function firing just by mentioning the variable?
I thought this was to do with using parentheses, but there aren't any involved so it can't be?
Thanks,
1DMF
"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music