0

I'm having issues with a script that I made for use in HTML5. Here is the function

function loadImage(loc,after,para){
        var img = new Image();
        img.src = loc;
        if(typeof(after) != "undefined" && typeof(para) != "undefined"){
            img.onloadeddata  = after(img,para);
        }else if(typeof(after) != "undefined"){
            img.onloadeddata  = after(img);
        }
        return img;
}

and here is what is calling it

window.globalFriends[i][2]=loadImage('http://graph.facebook.com/'+window.globalFriends[i][0]+'/picture', function (a){
    updateLoaders();
    loadingDrawPerson(a);});

What I'm trying to do is send a function as a parameter for it then to be called. It kinda of works but it a weird way. For example; All the images do get loaded but the onloadeddata either fires the function way to early or the function is getting executed before it gets to the loadImage function.

What are your ideas on my malfunctioning script?

Thank-you for reading Paul

1
  • typeof is an operator, not a function so there is no need for a grouping operator after it. Use: typeof after Commented May 16, 2011 at 23:36

2 Answers 2

3

A line like this:

img.onloadeddata  = after(img,para);

Means "call the after function with arguments img and para" and assign the result to onloadeddata." If, instead, you're wanting to assign the function to onloadeddata, do this:

img.onloadeddata = function() { after(img, para); };
Sign up to request clarification or add additional context in comments.

Comments

1

It's img.onload And it needs a function.

Try

img.onload = function() {
    after(img, para);
}

I think your missing the para parameter

window.globalFriends[i][2]=loadImage('http://graph.facebook.com/'+window.globalFriends[i][0]+'/picture', function (a){
    updateLoaders();
    loadingDrawPerson(a);}/*, para */); // <- where is para?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.