2 Replies Latest reply on Jul 11, 2006 12:30 PM by Peter Lorent

    help in scoping problem

    corrodedlotus
      i created a class for my game and i've been having problems accessing my variables. i know its a scope problem(i think) so can anyone just point it out for me? i have been stumped for teh past hour on this so i figured i'll just ask for a little help.

      the problem is i cant get the fourLetters array. What this program does is create a jumbled word which falls down the screen. when you type the answer correctly, another word appears etc.

      problem is, when i call creatword again and input parentObj.fourLetters or parentObj.getCurrentList() as a parameter, it says it is undefined. it worked the first time but why not the second time? what happens to my array during this time?

      any help would be appreciated. Thanks!

      by the way, the code is included here:

        • 1. Re: help in scoping problem
          mxc
          In gerneral avoid using _root and always test the this property with a trace to make sure it is correct.
          I think it would help the answer if you included the timeline code too so it is possible to see how the Array is called.

          best regards
          Michael

          • 2. Re: help in scoping problem
            Peter Lorent Level 2
            >>it worked the first time but why not the second time?
            Most likely you are using instance properties (fourLetters, fiveLetters) to save the LoadVars data. Then you create a new instance but do not load the data again assuming it's already there. And when you are using instance properties, it's not. The properties fourLetters and fiveLetters are defined per instance. A way to solve this is by using class properties making the content static for all instances of the class.

            private static var fourLetters:Array;
            private static var fiveLetters:Array;