5 Replies Latest reply on May 3, 2007 8:45 AM by TimTee

    this keyword inside object

      I'm using this:

      imageLoader_listener.onLoadInit = function(target_mc:MovieClip) {

      the only way I know how to access variables I set in target_mc is by using the array access like this...


      but I can't use this inside an object because it refers to the object.

      How do I deal with this? Do I have to make a separate function with these statements that gets called for the object?

      Thx, a little confused with this, I've run into this a few times any clarification is appreciated.
        • 1. Re: this keyword inside object
          dr_ross Level 1
          why not just type target_mc.theVar as in

          myListener.onLoadInit = function(target_mc)
          target_mc._alpha = 20
          target_mc.myVar = 2000;
          • 2. this keyword inside object
            dr_ross Level 1
            dble post
            • 3. Re: this keyword inside object
              TimTee Level 1
              crap. You're right. What I was doing was creating empty movieclips and setting vars in them, and then loading images into them. But loading images into them seems to wipe out the variables I set. So then using target_mc.theVar returned undefined.
              • 4. Re: this keyword inside object
                Rothrock Level 5
                Here is part of the difference. Noticing what class type something is: So if you have code that looks like this:

                var home:MovieClip=this;
                var target1:String="someClipName1";
                var target2:MovieClip=home.someClipName2;


                This assumes that someClipName1 and 2 both exist on the same timeline as this code. Notice how the first reference target1 is a string. In that case you need the array access to say "Look inside of home for something called by the value of this string, namely someClipName1." The other one, target2, is of type movieclip so Flash already knows that it is a movieclip.

                So when you read the help files for things like MovieClipLoader.onLoadInit you can notice what types it returns and then know exactly how handle them. And you are correct when you load external content it will wipe out any variables/properties you set earlier.
                • 5. this keyword inside object
                  TimTee Level 1
                  thanks very much for taking the time to explain. Think I get this now.

                  Yea the trouble spot for me was not realizing the variables get zapped when loading a jpg into the clip. So I thought I was referencing wrong.