dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: % preloader a/s help plz

  1. #1
    FK's Official Cricket Eater. ViperGeckoFreak's Avatar
    Join Date
    Feb 2002
    Location
    In a Cage.
    Posts
    575
    ok..i am learning this out of flash mx magic, but i cant see my problem...when i test it says "NaN% loaded"
    instead of the number. could some a/s experts check my code plz

    Code:
    function preload(preloadContent) {
    	preloader._visible = 1;
    	preloader.display.text = "0% loaded";
    	intervalId = setInterval(preloadCallback, 10, preloadContent);
    }
    function preloadCallback(preloadContent) {
    	var download = 0;
    	var downloaded = 0;
    	var percentLoaded = 0;
    	
    }
    
    download = preloadContent.getBytesTotal();
    downloaded = preloadContent.getBytesLoaded();
    percentLoaded = Math.ceil(downloaded / download*100);
    
    preloader.display.text = percentLoaded + "% loaded"
    updateAfterEvent();
    
    if (downloaded == download && download >0) {
    	clearInterval(intervalId);
    	preloader._visible = 0;
    }

    thanks

  2. #2
    www.intensewd.com
    Join Date
    Apr 2002
    Location
    Australia
    Posts
    450
    wow!

    that is one UGLY pile of actionscript for a preloader...no offence...

    sometimes simple is best:

    put this code on frame 1:

    Code:
    total = _root.getBytesTotal() / 1024;
    received = _root.getBytesLoaded() / 1024;
    percentage = (received / total) *100;
    percenttext = int(percentage) add "%";
    a couple of frames later put this code:
    (this determines how frequently percentage is updated, based on movie framerate)

    Code:
    if (percentage == 100) {
    	do something!
    } else {
    	gotoAndPlay(1);
    }
    cheers,
    Ben

  3. #3
    chatbugs.com ***** flashTampaDotCom's Avatar
    Join Date
    Mar 2002
    Location
    Tampa, Florida
    Posts
    171
    http://www.flashtampa.com/flashtutor...epreloader.swf
    http://www.flashtampa.com/flashtutor...epreloader.fla

    ..has some good code and comments to learn from and use; I made it based on requests like yours. The swf includes a 100K image to demonstrate the preloader; otherwise, the code is under a few K.. Take a look.

  4. #4
    FK's Official Cricket Eater. ViperGeckoFreak's Avatar
    Join Date
    Feb 2002
    Location
    In a Cage.
    Posts
    575
    Originally posted by benlowry
    wow!

    that is one UGLY pile of actionscript for a preloader...no offence...

    sometimes simple is best:

    put this code on frame 1:

    Code:
    total = _root.getBytesTotal() / 1024;
    received = _root.getBytesLoaded() / 1024;
    percentage = (received / total) *100;
    percenttext = int(percentage) add "%";
    a couple of frames later put this code:
    (this determines how frequently percentage is updated, based on movie framerate)

    Code:
    if (percentage == 100) {
    	do something!
    } else {
    	gotoAndPlay(1);
    }
    cheers,
    Ben
    thx...works great

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