logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > Javascript and JS frameworks
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 03-27-2011, 04:57 PM   #1
Adam_C
 
Join Date: Feb 2009
Posts: 129
Default run function after other functions

Hi, i am creating a web application, and in it I use two functions do determine whether or not a user is logged in to flickr and/or facebook, then depending on where they are logged in, it loads the respective photos.

my only problem is how do i make sure the 'loadPhotos()' function runs only after I have filled arrays with photo information (i.e. name, link etc).

for example,

Code:
function getFbPhotos() {
    //use fb api to fill arrays
    names.push(name);
    links.push(link);
}

function getFlPhotos() {
    //use flickr api to fill arrays
    names.push(name);
    links.push(link);
}

function getAllPhotos() {
    //contact fb and fl arrays
}

function loadFbPhotos() {
    //fill divs with array info
}

function loadFlPhotos() {
    //fill divs with array info
}

function loadAllPhotos() {
    //fill divs with array info
}

function loadPhotos() {
    if (loggedInToFb() == true && loggedInToFl() == false) {
        loadFbPhotos();
    } else if (loggedInToFb() == false && loggedInToFl() == true) {
        loadFlPhotos();
    } else if (loggedInToFb() == true && loggedInToFl() == true) {
        loadAllPhotos();
    } else {
        //cant do anything
    }
}

function mainFunction(){
    getFbPhotos();
    getFlPhotos();
    getAllPhotos();
    loadAllPhotos(); //HERE IS THE PROBLEM
}
I hope this is easy enough to understand...

p.s my code is a bit more complex than this and uses object and other functions, but if you could use the functions above as a 'simple' way of solving this problem, then i could implement it into my code.

thanks for reading
__________________
http://adamscarter.co.uk/
Adam_C is offline   Reply With Quote
Old 03-28-2011, 02:14 AM   #2
ranjan
 
Join Date: Dec 2004
Posts: 405
Default Polling for loaded content

http://ajaxian.com/archives/polling-...ple-settimeout
ranjan is offline   Reply With Quote
Old 03-28-2011, 01:19 PM   #3
dahliacreative
 
Join Date: Feb 2011
Posts: 7
Default

Just fire the function from within the first function for example:

function loadPhotos () {
}

function dothisfirst () {
do lots of stuff in here.
dothissecond();
}

function dothissecond () {
do lots of stuff in here.
loadPhotos();
}
dahliacreative is offline   Reply With Quote
Old 03-28-2011, 08:11 PM   #4
Adam_C
 
Join Date: Feb 2009
Posts: 129
Default

Quote:
Originally Posted by ranjan View Post
Thanks, I'm pretty sure this is what I'm looking for however, I don't really know how I would implement this into my code, namely the arguments part. I have got the function in the right place, however my function which gets the photo information fills an array. I have tried removing the 'window' section in the function 'executeWhenLoaded' because the variable I am waiting to load is in an object (more specifically 'myObject.photoFeed.Facebook.thumbNames').

How would i put that into the arguments?
__________________
http://adamscarter.co.uk/
Adam_C is offline   Reply With Quote
Old 03-29-2011, 04:51 AM   #5
ranjan
 
Join Date: Dec 2004
Posts: 405
Default

Easiest ways is to create global variable flags like
Code:
var isAllPhotosLoaded = false;
Once the function loadAllPhotos executes set this flag to true.

And poll for true values, use the simpler setTimeOut method

Code:
function startPolling() {
    setTimeout('pollForEvents()', 100);
}
function pollForEvents() {
    if (isAllPhotosLoaded === true && isAnyOtherCheck === true) {
        
             //do something with the event
        
    } else {
             //poll again soon
             startPolling();
    }
}
Once this works read about arguments http://www.seifi.org/javascript/java...arguments.html
https://developer.mozilla.org/en/Jav...cope/arguments

Then go visit the previous link
ranjan is offline   Reply With Quote
Old 03-29-2011, 01:52 PM   #6
Adam_C
 
Join Date: Feb 2009
Posts: 129
Default

That works perfectly ranjan! thank you so much Seems there is still a lot more to learn in JS...
__________________
http://adamscarter.co.uk/
Adam_C is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:08 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com