5 Replies Latest reply on Dec 2, 2007 5:02 PM by kglad

    loading a movieClip from a class

    imaginari
      Hello all,

      I'm attempting to write an AS 2.0 class using Flash through which I can load and control multiple movie clips in the library and from external files. I've attempted multiple different ways, don't quite seem to be able to get the images to show up on the screen. After some time searching, I've been unable to find a good example online. Please excuse my inexperience with AS classes.

      I'd like to write a class that extends MovieClip and is used to control multiple 'sub' movieClips, all from methods inside the instantiated class.

      From .fla file, I call instantiate my class as follows:

      var theScene:sphere3D = new sphere3D();

      In the constructor of my class file, I'm attempting to attach or load a movie. I simply want to get it to show up on the screen, when I test the .fla movie. I've tried using attachMovie and loadMovie with not luck.

      dynamic class sphere3D extends MovieClip {
      function sphere3D() {
      this.attachMovie("shadow","shadow",1); // shadow being a movie clip in the .fla library with linkage
      shadow._x = 100;
      shadow._y = 100;

      this.createEmptyMovieClip ("shadow2", 100);
      shadow2._x = 100;
      shadow2._y = 100;
      shadow2.loadMovie("images/cube.png");
      }
      }

      What am I doing wrong? Suggestions for stuff to test would be welcome.

      Thank you,

      dana.
        • 1. Re: loading a movieClip from a class
          kglad Adobe Community Professional & MVP
          pass a reference to your timeline (in your constructor) that can use to attach your shadow movieclip.
          • 2. Re: loading a movieClip from a class
            imaginari Level 1
            quote:

            pass a reference to your timeline (in your constructor) that can use to attach your shadow movieclip.

            Thanks for the reply. Though I'm not sure I understand. Do you mean that attaching a movie doesn't work from within a class, or to a class instance? In what way should I pass a reference to the timeline? From the class constructor, I was able to attach a movie clip to _level0. But my hope is to be able to have all the attached objects be within the instance of the class so they can be controlled together, if this is possible of course.

            dana.
            • 3. Re: loading a movieClip from a class
              kglad Adobe Community Professional & MVP
              pass a reference to the timeline to which you want to attach your library clip:

              • 4. Re: loading a movieClip from a class
                imaginari Level 1
                Ah, thank you, that make sense now. The solution you suggested worked great.

                I did also find two other solutions, for anyone else who might read this. One is to essentially create an empty movieclip on your timeline. From the linkage window for the empty movieclip, I made sure I set the Class field to the name of the class I'd written, something I didn't do previously. This attaches all the class actionscript to the empty movieclip, and even automatically runs the constructor when the empty movieclip is placed on the timeline. It also automatically provides a 'reference' to the main timeline when I refer to this.attachMovie() from inside the class. So it worked, but isn't as elegant as doing everything from the actionscript (unless you are building a component).

                The last reference I came across is the Object.registerClass() method used to attach as class to an object, similar to using the Linkage method above. But I haven't successfully tried it yet.

                Thanks again for the help kglad,

                dana.
                _______

                Dana Sheikholeslami
                Art Institute of California
                • 5. Re: loading a movieClip from a class
                  kglad Adobe Community Professional & MVP
                  you're welcome.