3 Replies Latest reply on May 1, 2006 6:49 PM by Scottie0

    Problem Returning Values From Functions

    Scottie0 Level 1
      Flash MX2004
      I'm trying to create a game similar to Lingo, if you've ever seen it on TV. I had a bit of code that was working before I decided to break it out into functions.... specifically I'm trying to return values from 2 functions, and I'm getting nothing back. When I do a trace it comes back undefined. Can anyone have a look at this code to see if there's something really wrong with it?

      Any help greatly appreciated!

      ScottieBitter
        • 1. Re: Problem Returning Values From Functions
          Rothrock Level 5
          Well it looks like you have return myWordList outside of the onLoad function. So it is trying to return the array before it has loaded.

          Also you shouldn't use boolean value "true" for the name of an argument in a function, if (true) will always be true because that is what it is! So change that to something like success or figtree, but not another reserved word!

          It would also seem that lingoWord is a string, not an array. Unless the elements of myWordList are arrays then lingoWord isn't going to be an array.
          • 2. Re: Problem Returning Values From Functions
            Craig Grummitt Level 3
            If i'm interpreting your code correctly, it looks as though you're doing things in the wrong order - first you pick a word at random from a list, and then you fill the list. This would work better if you fill the list and then pick a word at random.

            remove the return value in your loadWords function because you haven't populated your list until the onload handler is called. move the line "var myWord:Array = pickWord(myWordList);" into your myWordLoader.onLoad handler - (after "trace(myWordList);") and it should pick a word okay at random from your text file. fingers crossed!
            • 3. Re: Problem Returning Values From Functions
              Scottie0 Level 1
              Rothrock, Craig,

              Thank you both for your help. I applied your suggestions, and now my traces are coming back with results I expect!
              Awesome!

              Now to keep working on this stuff.... it's an assignment for a class due tomorrow, and I have a long way to go.... <sigh>

              ScottieBitter