5 Replies Latest reply on Apr 19, 2006 2:16 PM by ogousa-swS9lV

    Problem with getting a variable to display proper value

    DuhChamp
      Ok. So now I have the proper value stored inside of my class variable, but when I use my getRules() function, it returns an undefined. The only way I can get it to return the proper value is to use it inside an onEnterFrame = function() and then trace it out each frame, but I only want to trace it once. I understand that the value has to load in on the first frame, but why is it not working when I create multiple frames and call the trace value then?

      The class variable is properly defined, as I can check it through the debug menu, and like I said, I can actually see it repeat itself in my onEnterFrame function (when I do that, it comes out undefined for the first frame, then has the correct value for each additional frame).
        • 1. Re: Problem with getting a variable to display proper value
          ogousa-swS9lV Level 1
          getRules() should be the member of your class or your class variable should be public.
          Could you please show the part of your code to make it clear?


          Thanks,
          ogousa
          Matter of Time
          • 2. Re: Problem with getting a variable to display proper value
            DuhChamp Level 1
            getRules is a method of my class. Here it is.

            public function getRules():String
            {

            return this.m_Rules;
            }

            m_Rules is a private member of my class, here is how i define it

            private var m_Rules:String;


            I've been doing some experimenting while waiting for an answer, and I found a weird result. If I place the myClass.getRules() on any frame after 2, it works, but if I place it on either frame 1 or 2, i need to use it inside an onEnterFrame function!!! Any ideas as to why that happens?
            • 3. Re: Problem with getting a variable to display proper value
              ogousa-swS9lV Level 1
              I created myClass.as with the following content:

              class myClass
              {
              private var m_Rules:String;

              function myClass()
              {
              m_Rules = "ddddddddd";
              }

              public function getRules():String
              {
              return this.m_Rules;
              }
              }

              In the first frame I enter:

              aaa = new myClass();
              trace(aaa.getRules());

              It returns me ddddddddd.
              Compare this code with your - maybe you will find the bug.

              ogousa
              Matter of Time
              • 4. Problem with getting a variable to display proper value
                DuhChamp Level 1
                That works just fine, but now try loading a variable from an external source using loadvars like i am doing. It will not work. Here is my code.

                In my constructor I call setRules, which does the following code:

                var rulesLoader:LoadVars = new LoadVars();

                rulesLoader.onData = mx.utils.Delegate.create(this, assignText);

                rulesLoader.load("external.txt");

                The Delegate class calls the assignText with the this scope. Here is the assign text function:

                private function assignText(sText:String):Void
                {
                this.m_Rules = sText;

                }


                Like i said, the variable does get the correct value, but for some reason I cannot trace it or access the correct value until the third frame of action, or unless I create an onEnterFrame function.
                • 5. Re: Problem with getting a variable to display proper value
                  ogousa-swS9lV Level 1
                  onEnterFrame() handler is executed once for every tick of the framerate. It looks like your movie waits for loading variables
                  in the first frame. The movie stays on the first frame for some time and onEnterFrame() executes many times - that's why you can use trace() inside onEnterFrame(). But it is not clear why you can not use trace() on the second frame, sorry
                  It should be investigated. Try to change framerate from very small to very big and see what happens.

                  ogousa
                  Matter of Time