A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Freezing Loops

  1. #1
    Senior Member SpikeyOmega's Avatar
    Join Date
    Dec 2004
    Posts
    400

    Freezing Loops

    Hey, I am making something that searches through a starting amount of 200 words, and then if it finds that an entered word doesnt match any of those, it adds it to those 200. Here is the starting script (manual word is the entered word to be checked).
    code:

    function prepare2(){
    words.toLowerCase();
    manualWord.toLowerCase();
    for (t = 1; t <= totalWords; t++){
    if (words[t] == manualWord){
    wordNumber = t;
    detected = 1;
    }
    }
    return detected;
    matches = undefined;
    typeGame = undefined;
    wrongText = "";
    aG = false
    bG = false
    cG = false
    dG = false
    eG = false
    fG = false
    gG = false
    hG = false
    iG = false
    jG = false
    kG = false
    lG = false
    mG = false
    nG = false
    oG = false
    pG = false
    qG = false
    rG = false
    sG = false
    tG = false
    uG = false
    vG = false
    wG = false
    xG = false
    yG = false
    zG = false
    if (detected == []){
    addWord(manualWord);
    }
    redirectTwo();
    }


    Heres is the addWord() function, and all the things related to it:
    code:

    //Saving
    var saver:SharedObject = SharedObject.getLocal("tester4");
    if (saver.data.playedBefore == undefined){
    saver.data.playedBefore = true;
    saver.data.savedWords = words;
    var totalWords:Number = 200;
    saver.data.totalWords = totalWords;
    saver.flush();
    trace(saver.data.totalWords);
    }else{
    words = saver.data.savedWords;
    }
    function addWord(newWord){
    totalWords ++;
    wordNumber = totalWords;
    saver.data.totalWords = totalWords;
    words[totalWords] = newWord;
    saver.data.savedWords = words;
    saver.flush();
    }


    Now, whenever it performs the loop, the alert popup that says it is running slowly comes up. Is there a way to fix this problem?
    Last edited by SpikeyOmega; 06-18-2005 at 07:12 PM.

  2. #2
    the usual
    Join Date
    Jul 2000
    Posts
    1,482
    Code:
    // testing - populate an array (words)
    var words = new Array ();
    for (var i = 0; i < 200; i++)
    {
    	words.push ('word' + i);
    }
    // changed the way the word is passed to the function
    function prepare2 (word)
    {
    	// convert the word to lowercase
    	var mwc = word.toLowerCase ();
    	for (t = 1; t <= words.length; t++)
    	{
    		if (words[t].toLowerCase () == mwc)
    		{
    			// if there is a match stop the loop
    			return true;
    		}
    	}
    	// if we've reached here - the word is not in the array, so add it
    	addWord (word);
    	redirectTwo ();
    	// end the function
    	return false;
    }
    // simulated
    function redirectTwo ()
    {
    	trace ('redirectTwo');
    }
    // simulated to show it working
    onMouseDown = function ()
    {
    	// word will be addd on mouse down - testing
    	prepare2 ('notinarray');
    	// word is already in array - not added
    	prepare2 ('word2');
    };
    //Saving
    var saver:SharedObject = SharedObject.getLocal ("tester6");
    if (saver.data.savedWords == undefined)
    {
    	saver.data.savedWords = words;
    	saver.data.totalWords = words.length;
    	trace (saver.data.totalWords);
    }
    else
    {
    	words = saver.data.savedWords;
    }
    function addWord (newWord)
    {
    	trace ('adding word');
    	saver.data.savedWords.push (newWord);
    	saver.data.totalWords = words.length;
    }

  3. #3
    Senior Member SpikeyOmega's Avatar
    Join Date
    Dec 2004
    Posts
    400
    Thanks!

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center