3 Replies Latest reply on Jun 19, 2007 8:07 AM by the_lar222

    OOP scope question

    the_lar222
      Hi All,

      I'm struggling a bit with OOP and variable scope, can anyone explain why this isn't working... below is my class that is attached to a Movie clip on my main timeline

      This loads some variables from a PHP file into myVars, when the variables have loaded I want to set one of the class variables (theWord) to the value of word which is a variable loaded into myVars, but no matter what I try I can't do it. The code below is setting an addtional varible inside myVars called theWord which I don't want at all.

      I know its something to do with the scope, but I would really can't find a way of doing this!

      Thanks
      Kevin

        • 1. Re: OOP scope question
          kglad Adobe Community Professional & MVP
          i don't see an actionscript problem.

          are you sure your php file is returning:

          word=blah blah blah

          ??

          are you sure you don't have a security violation? have you tried using a script local to the server that contains your class?

          • 2. Re: OOP scope question
            Level 7
            Since you said the code is setting theWord inside your myVars object, then I
            think you do have a scope issue. And you do - even if the PHP weren't
            working properly - the onLoad method is called in the scope of the LoadVars
            object - so if you want to set a class variable from within it, you can pass
            the class scope in before calling load:

            class com.blurredistinction.Loader {
            var myVars:LoadVars;
            var theWord:String;

            function Loader(){
            myVars = new LoadVars();
            this.myLoadVars();
            }

            function myLoadVars(){
            myVars.onLoad = function(){
            trace("The word is: " + this.theWord);
            this.theClass.theWord = this.theWord;
            }
            myVars.theClass = this;
            myVars.load(" http://www.blurredistinction.com/test/random.php");
            }
            }

            Before calling load, set theClass variable inside myVars to this - the class
            scope. Then within onLoad you can say this.theClass to get the class scope -
            and I think you want this.theWord... not just theWord.

            --
            Dave -
            Head Developer
            http://www.blurredistinction.com
            Adobe Community Expert
            http://www.adobe.com/communities/experts/


            • 3. Re: OOP scope question
              the_lar222 Level 1
              Hi Dave,

              Brilliant, thank you for your explanation, makes perfect sense now! A bit trippy but I do get it!

              Kevin