3 Replies Latest reply on Feb 25, 2009 7:28 AM by Rothrock

    Why does this. work?

      For once the question is not why something did not work, but why it did work.

      I am an occasional user of actionscript, but create lots of small e-learning applications using loadMovie(), and it has worked perfectly for me time after time.

      Today, for no reason I could not get loadMovie() to work even though my procedures were exactly as I had them in the past.

      e.g loadMovie("howto.swf", howto)

      After 3 hours of trying everything I could think of, from the deep recesses of my memory a liitle glimmer came to me, and in my empty flash movie I put this.loadMovie() - which worked first time

      e.g. this.loadMovie("howto.swf", howto)

      I recognise that this is a simple/newbie question, but can someone tell me what is the significance of using this.

      Should have been using it all along, and have I just been lucky that this little disaster didn't happen earlier
        • 1. Re: Why does this. work?
          Level 7
          There's really no way to know why it worked in this instance without the
          context, as 'this' refers to the currently executing scope. You should get
          in the habit of using it though, as it can help you to know your intentions
          six months later when you open your file - ie you know into which
          timeline/scope you want to load. I'd also suggest ditching loadMovie and
          using the much better MovieClipLoader class.

          Dave -
          Adobe Community Expert

          • 2. Re: Why does this. work?
            Ned Murphy Adobe Community Professional & MVP
            It's a good question, and I'd be curious to know the definitive answer. According to the Flash docs there is the loadMovie global function and the loadMovie method of the movieclip class.

            Just about every example I could find in the docs uses the global approach. So to have a case like this where one works and the other doesn't, it would be good to know why. What is the difference in context that leads to this. The program apparently knows what that is, so whoever designed the program probably knows what it is, so it should be explainable.

            Unfortunately, the mystery may remain since there's probably enough on their plate to figure out what's going on in the present, nevermind digging into the past to better explain it.
            • 3. Re: Why does this. work?
              Rothrock Level 5
              Well this.loadMovie("howto.swf",howto) shouldn't work the same at all as loadMovie("howto.swf",howto).

              So my guess is that the movieclip instance howto wasn't created when the first one was trying to load howto.swf into the instance of howto. Because that is what that one is trying to do.

              The next one is trying to load howto.swf into this and pass a GET or POST which is most likely undefined.

              To use the second one in the same way as the first one it should probably look like:


              So, I'm just guessing here, but...I think the reason this works is because it provides loadMovie a qualified movieclip instance, whereas your other one isn't working because howto isn't a valid movieclip at the time the statement is called.

              In any event it really is time to stop using loadMovie and start using the MovieClipLoader class. Really!