A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: code problem while online

  1. #1
    Member
    Join Date
    Oct 2006
    Posts
    79

    code problem while online

    hi
    i have created a dynamic photo gallery that counts the amount of images in a folder (found the code somewhere) and displays the thumbs. It works perfectly offline but not online or while i am using the 'simulate download' feature. I have figured that somehow it hasn't got enough time to count the images or something.

    heres the code that counts the images:

    Code:
    stop();
    
    var NumImages:Number = 0; 
    function ImageExists(Num) { 
        var LV:LoadVars = new LoadVars(); 
        LV.onLoad = function(ok) { 
            if (ok) { 
                NumImages += 1; 
            } 
        }; 
        LV.load("gallery"+"/"+Num+".jpg"); 
    } 
    for (i=1; i<300; i++) { 
        ImageExists(i); 
    } 
    function ShowNumImages() { 
        trace("Number of images found: "+NumImages); 
    	   clearInterval(Update); 
    
    } 
    Update = setInterval(ShowNumImages, 1000);
    Please help me with the problem.

  2. #2
    Ryan Thomson EvolveDesigns's Avatar
    Join Date
    Oct 2001
    Location
    British Columbia
    Posts
    3,338
    try this instead (untested)

    PHP Code:
    stop();

    var 
    NumImages:Number 0;
    function 
    ImageExists(Num) {
        var 
    LV:LoadVars = new LoadVars();
        
    LV.onLoad = function(ok) {
            if (
    ok) {
                
    NumImages += 1;
            }else(
    ShoeNumImages());
        };
        
    LV.load("gallery"+"/"+Num+".jpg");
    }
    for (
    i=1i<300i++) {
        
    ImageExists(i);
    }
    function 
    ShowNumImages() {
        
    trace("Number of images found: "+NumImages);

    the code u posted was using a setInterval to retrieve the number of images at the end of one second rather than just using the onLoad(ok) function used which is weird.. probably coded by one person then hacked by another.. o well give mine a try, it should work for ya!
    Evolve Designs Interactive Media
    the natural selection

  3. #3
    Member
    Join Date
    Oct 2006
    Posts
    79
    thanks for your answer ryan, but theres a problem. your code only executes the ShowNumImages function if it hasnt found an image.

    Code:
    if (ok) {
                NumImages += 1;
            }else(ShoeNumImages());
        };
    I have tryed changing it and got into problems because once it has finished counting the images i need to - (gotoAndPlay(2).

    have you got any other ideas?
    thanks so much for your help!

  4. #4
    Ryan Thomson EvolveDesigns's Avatar
    Join Date
    Oct 2001
    Location
    British Columbia
    Posts
    3,338
    hello again!

    I must be confused, wouldn't you want the shownumimages function to only run once all the images are counted?

    If you want to goto frame 2 once all the images are counted you would just add
    gotoAndPlay(2); right after the trace in ShowNumImages
    Evolve Designs Interactive Media
    the natural selection

  5. #5
    Member
    Join Date
    Oct 2006
    Posts
    79
    hey
    it was confusing me too, i played around with that bit of code for ages and getting no where decided to recreate it using onEnterFrame. To my surprise it worked!

    here it is
    frame 1:
    PHP Code:
    stop();
    var 
    LV:LoadVars = new LoadVars();
    LV.load("gallery/"+(_root.galleryname)+"/thumb"+_root.ic+".jpg");

    LV.onData = function(src:String) {
        if (
    src == undefined) {
            
    this.onEnterFrame null;
            
    trace("Error loading content.");
            
    gotoAndPlay(3);
            return;
        }
        else{
            
    trace("ok");
        }
    };

    trace(LV);
    this.onEnterFrame = function() {
        
    trace("it is loading");
        var 
    loaded:Number LV.getBytesLoaded();
        var 
    total:Number LV.getBytesTotal();
        var 
    percent:Number int(loaded/total*100);
        
    trace(loaded);
        if (
    loaded>&& loaded>=total) {
            
    trace("loaded");
            
    // this.changepic.play();
            
    this.onEnterFrame null;
            
    gotoAndPlay(2);
        }
    }; 
    frame 2
    PHP Code:
    stop();
    if(
    _root.ic<300) {
                
    _root.tn ++; 
        
    _root.ic++;
    }
    gotoAndPlay(1); 

    thanks for your support ryan, your code helped me get to the solution.

  6. #6
    Ryan Thomson EvolveDesigns's Avatar
    Join Date
    Oct 2001
    Location
    British Columbia
    Posts
    3,338
    u bet! glad you got it working
    Evolve Designs Interactive Media
    the natural selection

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