preloading jpgs

Posted on 2006-06-05
Last Modified: 2010-04-03
hi there,

i have an app which loads several jpgs and once all are loaded, resizes an mc to reveal them.

the code is fairly complex, but basically, i use an onEnterFrame to track the bytes loaded against bytes total for all the jpgs (all fairly standard preloading stuff). and i have done ALOT of debugging around this stuff to find that it does only run the reveal script once all are supposedly loaded. however, i am getting blank spaces for a few seconds on some for their first loads in the live environment, which must mean that they are not completely loaded.

i remembered having a similar problem a few years back and putting it down to flash's loading of jpgs at the time, but i can't accept that is the case after so long as i am sure it would have been sorted out by now.

so, i am hoping someone might have an idea where i might be going wrong, or, if it isn't me, then perhaps a workaround that could solve this.
i would post the code if it weren't so complex... it'd take someone hours to figure out what's going on in there, so i can only hope this is something someone else has experienced before and found a solution to.

btw... am working for MX (flash 6) if it makes a difference.

Question by:nifmcm
    LVL 7

    Accepted Solution

    If you can use at least flash 7, then most of your problems would gone..
    there is a  funciton called :

    with it you can do many things like:

    getProgress which Returns the number of bytes loaded and the total number of bytes of a file that is being loaded

    loadClip Loads a SWF, JPEG, progressive JPEG, unanimated GIF, or PNG file

    if you won't use flash 7, then i think u better add your jpgs into a flash movie, and convert them into movie clips (don't forget to name its instances so u can control them later) , after doing so, you publsih you movie .
    you have now a swf containing all the jpgs you want...
    from the main movie, you can load the jpgs movie like nay ordinary movie (u can do a preloader ..etc)
    when the jpgs movie is loaded , you can user the jpgs inside using its instances name ..

    I hope this is clear for u


    LVL 2

    Assisted Solution

    I have this code from a photogallery I built a while back, it works for me and never shows the jpg's too early. Maybe something in here can help you.

    // SET JPG MC TO 100% SCALE
                _root.jpgMc._xscale = 100;
                _root.jpgMc._yscale = 100;
                maxWidth = 380;
                maxHeight = 319;

                _global.currentImage = _global.imgXML[_global.img].attributes.Image;
                _root.jpgMc._alpha = 0;
                this.onEnterFrame = function() {
                      //load bar
                      totBytes = eval(jpgMc).getBytesTotal();
                      actBytes = eval(jpgMc).getBytesLoaded();
                      percent = Math.round(actBytes*100/totBytes);
                      _root.loadingJpg.loadbar._xscale = percent;
                      _root.loadingNextPic_txt.text = "Loading Next Picture";
                      if(percent>0) {
                            _root.loadingJpg._alpha = 100;
                      if (percent>99) {
                            _root.loadingJpg._alpha = 0;
                            _root.caption.text = _global.imgXML[_global.img].attributes.Caption;
                            _root.loadingNextPic_txt.text = "";
                            _root.jpgMc._alpha = _root.jpgMc._alpha+20;
                            if (_root.jpgMc._alpha>99) {
                                  delete (this.onEnterFrame);
                            // SHRINK IMAGE IF IT IS TOO BIG TO FIT IN FLASH AREA
                            if (_root.jpgMc._height>maxHeight) {
                                  _root.jpgMc._height = maxHeight;
                                  _root.jpgMc._xscale = _root.jpgMc._yscale;
                            if (_root.jpgMc._width>maxWidth) {
                                  _root.jpgMc._width = maxWidth;
                                  _root.jpgMc._yscale = _root.jpgMc._xscale;
                                  _root.frame._width = _root.jpgMc._width+8;
                                  _root.frame._height = _root.jpgMc._height+8;

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
    The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
    The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
    The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now