SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trouble with Timing and Functions

    This is a two part question - please feel free to answer either question as one or the other will most likely fix the problem.

    The first question is about timing. Are setInterval and setTimeout the only good options in javascript? I need a 30 second pause in a loop in one function and assumed (from experience with other languages) that this was possible yet I have not been able to do it. (near the bottom)

    Code:
    function getFileList(folderSpec) {
    	var fs = new ActiveXObject("Scripting.FileSystemObject");
    	var folder = fs.GetFolder(folderSpec);
    	var en = new Enumerator(folder.Files);
    	var list = [];
    	
    	for (;!en.atEnd();en.moveNext()) {
    		list.push(en.item().Name);
    	}
    	return list;
    }
    function showFiles() {
    	var myList = getFileList("c:\\test\\swf files\\");
    	var myList2 =  getFileList("c:\\test\\jpg files\\");
    	var arrLength = myList.length
    	var arrLength2 = myList2.length
    	var loopSWF = 0
    	var loopJPG = 0
    	
    	while (loopSWF<=arrLength)
    	{
    	var a = myList[loopSWF]
    	var so = new SWFObject("swf files/" + a, "smw", "100%", "100%", "8", "#ffffff");
    	so.write("flashcontent")
    	loopSWF++
    	// PAUSE HERE FOR 30 SECONDS
    	}
    }
    The second question has to do with functions. I also did not realize that variables are not passed between functions. Is there an easy workaround for this? I have searched but have not found anything.

    If this is possible, the code below might work instead of the code above...
    Code:
    function showFiles() {
    	var myList = getFileList("c:\\test\\swf files\\");
    	var myList2 =  getFileList("c:\\test\\jpg files\\");
    	var arrLength = myList.length
    	var arrLength2 = myList2.length
    	var loopSWF = 0
    	var loopJPG = 0
    	loopFiles()
    }
    function loopFiles() {
    	while (loopSWF<=arrLength)
    	{
    	var a = myList[loopSWF]
    	var so = new SWFObject("swf files/" + a, "smw", "100%", "100%", "8", "#ffffff");
    	so.write("flashcontent")
    	loopSWF++
    	var t = setTimeout("loopFiles()",10000)
    	}
    }
    I am still new at this and any help is appreciated. I feel like I am so close to the finish line but I can't break the damn tape. If you need the rest of the code let me know. Thanks in advance for your time.

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not sure I get you, but about the "variables passed between functions", check out the var statement.

    You basically need to have global variables if you want to access them in different functions.

  3. #3
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you Thank you. I figured it was something like that but I couldn't find it. btw I searched global variables for javascript and found a good site

    http://www.webdevelopersnotes.com/tu...avascript.php3

    that explained a lot. Thanks again.


Bookmarks

Posting Permissions

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