3 Replies Latest reply on Jan 4, 2007 1:22 PM by Rothrock

    MovieClipLoader Lag

    BeniRose
      Hey guys. I'm trying to use MovieClipLoaders to load in these external pics to this flash website, but it's lagging like crazy. Here's a little chunk of my code:

      //set up our loader
      var loader:MovieClipLoader = new MovieClipLoader();
      listener = new Object();
      loader.addListener(listener);
      listener.onLoadInit = function(_mc:MovieClip){
      //code to resize the pic and what not goes here
      }

      Anyways, whenever I use this, if I have any timeline or Tween animations going on at the same time, they lag like crazy. Also, when I have a streaming sound object playing back, it also seems to clog this up a bit too. Does anyone have any suggestions to let the stuff load without interfering with eachother? Thanks in advance!

      ~Ben~

        • 1. Re: MovieClipLoader Lag
          Rothrock Level 5
          Don't think it is normal, unless you are running it on a very old system. Are you noticing this from the web or is it within the testing environment?

          Also there is certainly nothing with that part of the code that would be causing the problem. Unless of course the:

          //code to resize the pic and what not goes here

          Is more complex than a comment. :) or if you have an onLoadProgress listener that does a lot…

          Can you provide a link?
          • 2. Re: MovieClipLoader Lag
            BeniRose Level 1
            I don't have the site up yet, but I should have it soon. I've only tried it in testing, so I'm not sure exactly how it will load online. I'm running Flash 8 on a Macbook Pro, so I can't imagine that my processor is the issue! Anyways, here's the resizing code, it should be well handeled, but maybe you can tell me if i'm scratching nails on a chalkboard with this. I'll preface it by saying that I'm loading about 12 images into a photo gallery, that is 4 rows across (this is the value of the pics_per_row variable). All the loader demos I saw suggested I load my first picture and then when it's done loading, call my loader on the next image (stored in an array of xml nodes that look something like <image>whatever.jpg</image>). Anyways, here's the code inside my onLoadInit, it should be well commented:


            //complicated resizing crap
            var img_ratio = pic_width/_mc._width;

            //this simply checks to see if it should be resized by width or height and does so
            if (_mc._height*img_ratio > pic_width/2){
            //go by the width
            _mc._width = pic_width;
            _mc._height *= img_ratio;
            _mc._y = pic_width/4 - _mc._height/2;
            } else {
            //go by the height
            img_ratio = (pic_width/2)/_mc._height;
            _mc._height = pic_width/2;
            _mc._width *= img_ratio;
            _mc._x = pic_width/2 - _mc._width/2;
            }

            //mask the image
            _mc.setMask(_mc._parent.pic_mask);

            //create the onRelease
            _mc._parent.onRelease = function(){
            //get rid of our loading text and pic holder if they're there
            if (circles.loading_txt){
            circles.loading_txt.removeTextField();
            }
            if (circles.pic_holder){
            circles.pic_holder.removeMovieClip();
            }

            //reinstanciate our loading text and style it
            circles.createTextField("loading_txt",circles.getNextHighestDepth(),100,circles._height/2 -10,150,30);
            circles.loading_txt.selectable = false;
            circles.loading_txt.text = "Loading Image...";
            circles.loading_txt.setTextFormat(loader_fmt);

            //get our pic num by seeing what MC we just clicked on (they are named pic0, pic1, pic2, etc)
            pic_num = _mc._parent._name.substr(3,_mc._parent._name.length-3);
            //create the pic holder and place it where it belongs
            circles.createEmptyMovieClip("pic_holder",circles.getNextHighestDepth());
            circles.pic_holder._x = 68.1;
            circles.pic_holder._y = 68.1;
            //load it into the big pic loader, this isn't lagging very much, so don't worry about it
            big_pic_loader.loadClip("gallery/"+gallery[pic_num].firstChild, circles.pic_holder);
            }

            //test to see if we've loaded all our pics
            if (pics_loaded == total_pics-1){
            //if we have, remove our loading text and tween the alpha of all the pics to come up (this also doesn't lag)
            _root.content.content.loading_txt.removeTextField();
            for (var i = 0; i < total_pics; i++){
            TweenMe(pics ,"_alpha",NONE_NONE,30,100,15);
            }
            } else {
            //if we're not finished, goto the next pic
            pics_loaded++;
            //update our loading text to let us know what pic we're loading
            _root.content.content.loading_txt.text = "Loading "+pics_loaded+" of "+total_pics;
            _root.content.content.loading_txt.setTextFormat(loader_fmt);
            //set the alpha low
            _mc._parent._alpha = 30;
            //load the next picture
            loader.loadClip("gallery/"+gallery[pics_loaded].firstChild, pics[pics_loaded].pic_holder);
            }

            hope that helps!
            • 3. Re: MovieClipLoader Lag
              Rothrock Level 5
              It is hard to follow your code. When putting code into the forums you should copy it from the AS panel and then click the attach code button – only available if you "reply" not when using the Quick Reply.

              The forums change square brackets around i into italic and you also lose the indenting.

              One thing to think about is that the MovieClipLoader works differently in the testing environment (or when loading from a local machine) than it does over the internet. If this is to be delivered over the web, I would recommend finding a server and trying it from there. The problem may disappear.