Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: preloading

  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    672
    Thanks
    1
    Thanked 1 Time in 1 Post

    preloading

    I have a bunch of images with the names 20.gif through 2f.gif (following hex). I want them to all be preloaded in as short amount of script as possible. There's It's a nice trick to store variables in hex, but if you increment it through the FOR loop, or any other type of arithmetic, it converts it to base10. This isn't good. I had something more like this in mind:

    N=0x20
    for (i=N; i<0x30; i++)
    {
    "p"+i=new Image()
    "p"+i.src="'i'.gif"
    }

    Of course I could use Arrays, etc, but in the long run, it wouldn't be much shorter than 16 lines of preload script. Loading time is afterall a priority when preloading. What's a good preloading script for this?

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    0x20 or whatever is a perfectly legit Number literal, so just use that. All you need is the toString() method, which takes a radix for an argument (10 is default).
    Code:
    var hex, arrImgs = new Array();
    for (i=0x20, j=0x30; i<j; i++) {
    	hex = i.toString(16);
    	arrImgs["p"+hex] = new Image();
    	arrImgs["p"+hex].src = hex + ".gif";
    	}
    Last edited by beetle; 12-19-2002 at 10:13 PM.
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Posts
    672
    Thanks
    1
    Thanked 1 Time in 1 Post

    preloading

    Radix? I don't know what that is...But you mean it is that easy to convert a number to hex?

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The radix is the base of the number system. For binary, the base is 2, octal 8, decimal (our favorite) 10, and hex is 16.

    Javascript interprets the 0x20 as it's base 10 value, which in this case is 32. Applying [B]toString(16) gives us the hex value, again in this case, 20.

    Yes, it's that easy
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”


  •  

    Posting Permissions

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