A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Preloading external image3s

  1. #1
    Senior Member Bobby Hill's Avatar
    Join Date
    Feb 2004
    Posts
    243

    Preloading external image3s

    I have successfully done a tutorial at Kirupa about preloaders and transitions.
    http://www.kirupa.com/developer/mx/p...transition.htm

    My problem is that I have a swf file that loads external jpegs and I cannot get the tutorial to work correctly with this swf. It only preloads the the swf and not the external content that this swf is calling.

    Here is the code that I have on the main timeline of the home.swf

    PHP Code:
    var imgList:Array = new Array(); 
    imgList[0] = "images/image00.jpg"
    imgList[1] = "images/image01.jpg"
    imgList[2] = "images/image02.jpg"
    imgList[3] = "images/image03.jpg"
    imgList[4] = "images/image04.jpg"
    function 
    chooseTheString() { 
        
    randomPic random(imgList.length-0); 
        
    pics.loadMovie(imgList[randomPic]); 

    chooseTheString(); 
    _quality "best"
    stop(); 
    The rest of my swf files preload correctly but I just can't get it to preload this one correctly at all. I would appreciate any help that you can give.
    "My boss sits and watches TV in a hot dog suit and I think he might be a moron."

  2. #2
    All 1s and 0s dmonkey's Avatar
    Join Date
    Nov 2005
    Location
    Leeds, UK
    Posts
    606
    Hi,

    Flash won't preload images just becuase you have put references to them into an array. Images are only loaded when a 'loadMovie' command is passed. To get this to work, you will have to add to your preloader by loading in each movie one by one, which will be best achieved by making use of the MovieClipLoader class.

    Do you want me to create some code for you to show you how this would work?
    "If I have seen further, it is by standing on the shoulders of giants." - Sir Isaac Newton

  3. #3
    Senior Member Bobby Hill's Avatar
    Join Date
    Feb 2004
    Posts
    243
    That would be helpful, if you could.
    "My boss sits and watches TV in a hot dog suit and I think he might be a moron."

  4. #4
    Senior Member Bobby Hill's Avatar
    Join Date
    Feb 2004
    Posts
    243
    bump
    "My boss sits and watches TV in a hot dog suit and I think he might be a moron."

  5. #5
    All 1s and 0s dmonkey's Avatar
    Join Date
    Nov 2005
    Location
    Leeds, UK
    Posts
    606
    Sorry, I'll try and get this done by tomorrow at the latest!
    "If I have seen further, it is by standing on the shoulders of giants." - Sir Isaac Newton

  6. #6
    All 1s and 0s dmonkey's Avatar
    Join Date
    Nov 2005
    Location
    Leeds, UK
    Posts
    606
    Hi,

    I'm really sorry - I was positive I replied to this message. I even made a .fla for it which I subsequently deleted. Oh well, here's a better example anyway. Paste this code onto frame 1:

    code:

    //Our array containing our image data;
    var imgArray:Array = new Array();
    imgArray[0] = "http://freestockphotos.com/ANIMALS/BighornSheep4.jpg";
    imgArray[1] = "http://freestockphotos.com/ANIMALS/DeerWinter.jpeg";
    imgArray[2] = "http://freestockphotos.com/ANIMALS/Bullsnake22.jpeg";

    //etc...

    //Create an index variable we can use to check how many images have loaded;
    var imagesLoaded:Number = 0;

    //Create a MovieClipLoader
    var mcl:MovieClipLoader = new MovieClipLoader;

    //Create a listener object for the MovieClipLoader to catch events (like when the loading is finished);
    var listener:Object = new Object();

    //When loading starts, make a trace;
    listener.onLoadStart = function(target:MovieClip) {
    trace("Image "+target+" is loading");
    }

    //When loading finishes, imcrement imageLoaded;
    listener.onLoadComplete = function(target:MovieClip) {
    trace("An image has loaded");
    //Make invisible;
    target._visible = false;
    //Increment imageLoaded;
    imagesLoaded++
    //If we have no images left to load:
    if (imagesLoaded == imgArray.length) {
    trace("All images loaded");
    }
    }

    //Attach the listener to the MovieClipLoader;
    mcl.addListener(listener);

    //Loop through the array loading all images;
    for (image in imgArray) {
    var mc:MovieClip = this.createEmptyMovieClip("image"+image, this.getNextHighestDepth());
    mcl.loadClip(imgArray[image], mc);
    }



    Sorry about the screw up!
    "If I have seen further, it is by standing on the shoulders of giants." - Sir Isaac Newton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center