www.webdeveloper.com
Results 1 to 2 of 2

Thread: Passing in a variable through functions!

  1. #1
    Join Date
    Feb 2013
    Posts
    2

    Passing in a variable through functions!

    Help! I am trying to pass newsID into the final filename that is downloaded via phonegap in the below example.. The first alert reports that the newsID is working but then after that the variable is undefined? please can anyone suggest any advice?

    Thanks for any help in advance!

    Code:
     function downloadFileNews(newsID){
    	  
    
    	  alert ('downloading '+newsID);
    	  
    		  
    		  				
    								
    						window.requestFileSystem(
    									 LocalFileSystem.PERSISTENT, 0, 
    									 function onFileSystemSuccess(fileSystem,newsID) {
    									 fileSystem.root.getFile(
    									 
    
    																					
    												 "dummy.html", {create: true, exclusive: false}, 
    												 function gotFileEntry(fileEntry){
    												 var sPath = fileEntry.fullPath.replace("dummy.html","");
    												 var fileTransfer = new FileTransfer();
    												 fileEntry.remove();
    				 
    
    				 
    												 fileTransfer.download(
    														    "http://gwc.dreamshock.com/newsImages/thumbs/"+newsID+"_1.jpg",
    														   sPath + "22257_1.jpg",
    														   function(theFile) {
    														   console.log("download complete: " + theFile.toURI());
    														   showLink(theFile.toURI());
    														   },
    														   function(error) {
    														   console.log("download error source " + error.source);
    														   console.log("download error target " + error.target);
    														   console.log("upload error code: " + error.code);
    														   }
    														   );
    												 }, 
    												 fail);
    									 }, 
    									 fail);
    									 
    			
    					  
    			
     
        }

  2. #2
    Join Date
    Jan 2013
    Posts
    10
    I'm not sure where you're having trouble because your code formatting is wacky but here's a stab anyway:

    I think where you're having trouble is in the nested function: onFileSystemSuccess(fileSystem,newsID).

    What I suggest you try is set the variables locally in the function to pass through.

    Something like this:

    Code:
    yourMainFunction(newsID){
    var newsID = this.newsID;
    //other code executed and do that with the fileSystem parameter as well
    Hope this helps, if you better formatted the code I might be able to follow better.

    HOS

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles