dcsimg
A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: [RESOLVED] clearing a preloader

  1. #1

    resolved [RESOLVED] clearing a preloader

    Hello everyone,

    I have a little preloader problem. The code I have so far is provided below. I have 4 imgs in an array with four buttons that will load one of the imgs from the array. If I do a simulated test to see how the preloader is working everything works. I can see my preloader working the percent is shown in the output window.

    Here is my problem:
    If I click on a new button while an img is loading the preloader flips out.
    The percentage in the output window passes 100%. I think that the problem is the previous img being loaded gets loaded with the new img.

    How can I zero out the preloading process so that it will load the new img only?

    PHP Code:
    var loadImgs:Array = ["1.jpg""2.jpg""3.jpg""4.jpg"];

    btn1.buttonMode btn2.buttonMode =  btn3.buttonMode =  btn4.buttonMode true;

    btn1.addEventListener (MouseEvent.CLICKclicked1);
    btn2.addEventListener (MouseEvent.CLICKclicked2);
    btn3.addEventListener (MouseEvent.CLICKclicked3);
    btn4.addEventListener (MouseEvent.CLICKclicked4);

    var 
    imgLoader:Loader = new Loader();
    imgLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,fileLoading);

    function 
    clicked1 (e:Event):void 
    imgLoader.load(new URLRequest(loadImgs[0]));
    }

    function 
    clicked2 (e:Event):void 
    imgLoader.load(new URLRequest(loadImgs[1]));
    }

    function 
    clicked3 (e:Event):void 
    imgLoader.load(new URLRequest(loadImgs[2]));
    }

    function 
    clicked4 (e:Event):void 
    imgLoader.load(new URLRequest(loadImgs[3]));
    }

    function 
    fileLoading(event:ProgressEvent):void {
        var 
    percent:Number event.bytesLoaded/event.bytesTotal*100;
        
    loaderIndicator.width stage.stageWidth*percent/100
        
    trace(percent);
        if (
    event.bytesLoaded == event.bytesTotal) {
            
    addChild(imgLoader); 

        }

    Thank You in advance
    Last edited by mehmet22; 08-21-2009 at 12:07 PM.

  2. #2
    lemon juice hurts your eyes florianvanthuyn's Avatar
    Join Date
    Jul 2005
    Location
    Merelbeke, Belgium
    Posts
    546
    Try calling the imgLoader.unload() method before loading in one of the files.
    Florian Vanthuyne

    WAR AGAINST SOLVED THREADS
    mark yours as Resolved under Thread Tools!

  3. #3
    Thank you for the reply but that did not change anything. It did not even give any kind of a error.

    But in the output window I get this for the percentage as it starts loading the new image.

    PHP Code:
    11.005577802252839
    11.183083547366998
    11.360589292481157
    Infinity
    Infinity
    Infinity
    0.389229849701882
    0.45402050300223684
    0.5188111563025918
    0.6270115473141845 
    Any other ideas guys?
    Last edited by mehmet22; 08-20-2009 at 07:34 PM.

  4. #4
    lemon juice hurts your eyes florianvanthuyn's Avatar
    Join Date
    Jul 2005
    Location
    Merelbeke, Belgium
    Posts
    546
    You can also remove all the button eventListeners while loading, and add them again afterwards.
    And this might not work, but try it anyway imgLoader = null;
    Florian Vanthuyne

    WAR AGAINST SOLVED THREADS
    mark yours as Resolved under Thread Tools!

  5. #5
    Junior Member
    Join Date
    Oct 2007
    Posts
    26
    Hi

    I have the same problem and I am trying to solve it, I think you need to close() the loader when the user clicks another button, so that the preloader does not continue loading the old request. I am not sure how though!

  6. #6
    I have attached a zip of the latest file and all of the updates.
    I have tried removing the listeners and the percentage still passed 100%.
    using null gave an error about the is already null.

    Is this a bug in AS3.0?
    Attached Files Attached Files
    Last edited by mehmet22; 08-21-2009 at 12:07 PM.

  7. #7
    Appareantly this works online but it breaks when you do a simulated test from your desktop.

    Thanks for helping florianvanthuyn

    I have attached a zip corkg. Test it online to see it works. You will need to put images that are much larger to see the preloader.
    Last edited by mehmet22; 08-21-2009 at 12:13 PM.

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