3 Replies Latest reply on Jan 31, 2007 7:08 AM by Peter Lorent

    loadMovie cause problems with onEnterFrame method defined on  a class

    Quiltron
      Hello everyone

      I have just started to work with classes few days ago and i found this problem on my way.

      I have defined on a class a method that has to be executed every frame (onEnterFrame), but it doesnt works, the reason for the error is not on the class nor on the way i define the object of that class: its on a loadMovie() statement wich loads a picture on a movieClip. That movieClip is the class parameter, and when i use the loadMovie it stop the onEnterFrame method. Its very rare. To make the example work just put any image on the same folder with the name "Pic1". Thats all. (

      Code of an example below
      Copy the first code onto an .as file and save it as mySizer.as
      Copy the second code on a .fla and save it on the same folder of .as file
      Grab any jpg to that folder and name it as Pic1.jpg

      Any help would be apreciated
      Thanks in advance
        • 1. Re: loadMovie cause problems with onEnterFrame method defined on  a class
          Peter Lorent Level 2
          A few basic mistakes.

          var Container:MovieClip = this.createEmptyMovieClip ("Container",1)
          Container.loadMovie ("Pic1.jpg")
          var mySizer:Object = new mySizer (Container)
          mySizer.init();

          Now, this code executes right away. Meaning, it doesn't wait for the jpg to load and then creates the new instance of mySizer. Creation of the new instance of mySizer will be quicker, consequently the loadMovie() kills the event handler onEnterFrame. Solution: wait for the jpg to fully load (using the MovieClipLoader Class), then create the new instance of mySizer.

          var mySizer:Object = new mySizer (Container)
          If you datatype mySizer as an object you will loose datatype checking. mySizer is an object of type mySizer:
          var mySizer:mySizer = new mySizer (Container);
          But, you shouldn't name the instance mySizer since it is the name of the class. You can call methods in a class that are declared as public static directly. So, if you comment the line:
          //var mySizer:Object = new mySizer (Container)
          you'll see what will happen: the compiler thinks you are calling a method directly and the output panel traces an error.

          The class:
          class mySizer extends MovieClip{
          Extending the MovieClip Class (extending a class is known in OO as inheritance) AND using a constructor doesn't make sense. When you extend the MovieClip Class there needs to be a relationship with a movieclip in your library (using the linkage identifier). The instance gets instantiated by having a copy of that movieclip on the stage or by attaching it using MovieClip.attachMovie().

          When you declare:
          var Target:MovieClip;
          you are using what is known as composition. You save the functionality of the MovieClip Class in the instance property Target.

          I've rewritten the code and attached it. You'll notice the usage of the Delegate Class. Because - in the attached code - I'm using composition we can't use this._width anymore because mySizer doesn't have a property _width.


          • 2. Re: loadMovie cause problems with onEnterFrame method defined on  a class
            Quiltron Level 1
            Thanks buddy for the very complete reply, as a starter i really apreciatte it. :)