4 Replies Latest reply on Nov 4, 2006 1:54 AM by Peter Lorent

    OOP Question

    doonsbury Level 1
      Hoping someone can help. I've been introducing myself to OOP in Flash and have an issue. I've written a custom PreLoader class using MovieClipLoader and a Listener object. The code produces a good result but it seems that I am forced to use _root to reference properties inside two of my functions. If someone has experience with this I will send you the files and a bit more explanation. The class code is attached. Thanks in advance...
        • 1. Re: OOP Question
          Peter Lorent Level 2
          Inside callback handlers (example in your class: listener.onLoadProgress) the class members go out of scope. There are several ways to solve this. One is to use a local (local to the function) variable that holds a reference to the current object.
          public function PreLoader(target:MovieClip) {
          var thisObj:PreLoader=this;
          and inside the callback handler access the class members:
          thisObj.mcFiller =
          Another way is to use the Delegate Class (hit F1 and search for Delegate). But, in this case where you use the MovieClipLoader Class you can solve it simply by using the events from the MovieClipLoader. You use an object as a listener for the events so... use the current object. See attached class.

          • 2. Re: OOP Question
            doonsbury Level 1
            Thanks...looks like it makes sense. I'll try it this evening and report back (darn day job!!!).
            • 3. Re: OOP Question
              doonsbury Level 1
              Thank you very much for your suggestions. The code works very well and functions as a class should. Hope I can help someone else out soon.
              • 4. Re: OOP Question
                Peter Lorent Level 2
                Well, it's a class. But OOP is another thing. Split up the functionality. Have a class 'Rectangle' that takes care of drawing all kinds of boxes. A class 'TextOutput' that writes text fields. A class 'Loader' that handles loading of swf's or jpg's. Loader then uses PreLoader and PreLoader uses Rectangle and TextOutput. In that scenario you can reuse the Rectangle and TextOutput in other parts of your code.