3 Replies Latest reply on Jun 29, 2006 1:46 PM by Newsgroup_User

    _height is 0 after loadMovie

    DJ_James
      I'm dynamically loading a movie into a movie clip:
      _root.controlPanel.loadMovie(_root.movToLoad);

      Immediatly after, I try to get the height:
      _root.controlPanel._height

      It always returns 0... is there a way to make flash WAIT until the movie loads before getting the _height of it?

      I have FLash 8..
      thanks
        • 1. Re: _height is 0 after loadMovie
          Peter Lorent Level 2
          Use the MovieClipLoader Class to load and get or set the properties in the onLoadInit handler. The help files show you how you do this.
          • 2. Re: _height is 0 after loadMovie
            Jan-Paul K. Level 1
            var mcl:MovieClipLoader = new MovieClipLoader();
            var listener:Object = new Object();
            listener.onLoadInit = function(target_mc){
            trace(target_mc._height);
            }
            mcl.loadClip("my.swf",controlPanel);
            • 3. Re: _height is 0 after loadMovie
              Level 7
              DJ James,

              > I'm dynamically loading a movie into a movie clip:
              > _root.controlPanel.loadMovie(_root.movToLoad);

              Okay.

              > Immediatly after, I try to get the height:
              > _root.controlPanel._height

              You bet. That makes sense, too, right? Until that external content has
              loaded, the container clip has no height.

              > It always returns 0... is there a way to make flash
              > WAIT until the movie loads before getting the
              > _height of it?

              If you're using the MovieClip.loadMovie() method, which is what you've
              shown so far, then you need to loop repeatedly and check the values of
              MovieClip.getBytesLoaded() against the value of MovieClip.getBytesTotal()
              for the clip in question. You could use the MovieClip.onEnterFrame event to
              do the loop.

              _root.controlPanel.onEnterFrame = function() {
              }

              This assigns a function literal to the MovieClip.onEnterFrame event of
              controlPanel -- so it's going to do something. But what? Well, you want it
              to check the above mentioned methods, which return numeric values.

              _root.controlPanel.onEnterFrame = function() {
              trace(this.getBytesLoaded());
              trace(this.getBytesTotal());
              trace("---");
              }

              You can see all the available methods, events, and properties, by the
              way, by looking up the MovieClip class entry in the ActionScript 2.0
              Language Reference. All objects in Flash are defined by their namesake
              classes, and classes are all laid out for you in the built-in documentation.

              When loaded bytes are greater than or equal to the total bytes, you're
              done. In the next example, I'll use the _root itself (which is a movie
              clip, believe it or not) to do the looping. Note the slight difference in
              object references.

              _root.controlPanel.loadMovie(_root.movToLoad);
              _root.onEnterFrame = function() {
              if (this.controlPanel.getBytesLoaded() >=
              this.controlPanel.getBytesTotal()) {
              trace("done loading");
              trace(this.controlPanel._height);
              }
              }

              Make sense? Alternately, you could loop until the MovieClip._height
              property of controlPanel was something other than zero. That would amount
              to the same thing.

              For a completely different approach, check out the MovieClipLoader
              class, which features a number of events pertaining to loading.


              David
              stiller (at) quip (dot) net
              Dev essays: http://www.quip.net/blog/
              "Luck is the residue of good design."