JAVASCRIPT   9

LoadImageArray.js

Guest on 18th May 2021 04:36:24 AM

  1. ///
  2. //  LoadImageArray v 1.0
  3. //  Russell Lowke, March 1st
  4. //
  5. //  Copyright (c) Lowke Media
  6. //  see http://www.lowkemedia.com for more information
  7. //
  8. //  Permission is hereby granted, free of charge, to any person obtaining a
  9. //  copy of this software and associated documentation files (the "Software"),
  10. //  to deal in the Software without restriction, including without limitation
  11. //  the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12. //  and/or sell copies of the Software, and to permit persons to whom the
  13. //  Software is furnished to do so, subject to the following conditions:
  14. //
  15. //  The above copyright notice and this permission notice shall be included in
  16. //  all copies or substantial portions of the Software.
  17. //
  18. //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. //  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. //  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. //  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. //  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  23. //  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  24. //  IN THE SOFTWARE.
  25. //
  26. //
  27.  
  28. ///
  29. // Loads a number of image assets labeled from 0 to nImages into an Array.
  30. //
  31.  
  32. function LoadImageArray(path,                   // (string) path to image asset
  33.                         imageName,              // (string) name of image
  34.                         nImages,                // (uint) number of assets to be loaded
  35.                         type,                   // (string) file type sufix, eg ".jpg"
  36.                         obj,                    // object to assign asset to
  37.                         varName)                // variable on obj to assign asset to
  38. {  
  39.     this.asset  = new Array();                  // (array) array of images being loaded
  40.     this.nImagesLoaded = 0;                     // (uint) number of images loaded so far
  41.    
  42.     // KEEP THESE PUBLIC???
  43.     this.path       = path;
  44.     this.imageName  = imageName;
  45.     this.nImages    = nImages;
  46.     this.type       = type;
  47.     this.obj        = obj;
  48.     this.varName    = varName;
  49.    
  50.     this.startLoad = function()
  51.     {
  52.         for (var i = 0; i < this.nImages; ++i) {
  53.             var url = this.path + "/" + this.imageName + i + this.type;
  54.             AssetLoader.instance.loadFile(url, this.assign, [i], this);
  55.         }
  56.     }
  57.    
  58.     this.assign = function(image,               // (object) image being assigned
  59.                            index)               // (uint) index of image in asset array
  60.     {
  61.         this.asset[index] = image;
  62.         ++this.nImagesLoaded;
  63.         if (this.nImagesLoaded === this.nImages) {
  64.             this.fileLoaded();
  65.         }
  66.     }
  67.    
  68.     this.fileLoaded = function()
  69.     {
  70.         LogAs.debug("File loaded (" + this.id + "): " + this.url, AssetLoader.DEBUG_FILE_LOADED);
  71.         var evt = $.Event(LoadBase.ASSET_LOADED_EVENT);
  72.         evt.asset = this.asset;
  73.         $(this).trigger(evt);
  74.         this.assetLoader.removeAssetLoader(this);
  75.     }
  76.    
  77.     this.cleanup = function()
  78.     {
  79.         this.asset = null;
  80.     }
  81.    
  82.     this.toString = function() {
  83.         return "[LoadImageArray (url:" + this.url + ")]";
  84.     }
  85.    
  86.     this.initialize(this.path + "/" + this.imageName + "0-" + (this.nImages - 1) + this.type);
  87. };
  88.  
  89. LoadImageArray.prototype = new LoadBase();                  // LoadImageArray class extends LoadBase

Raw Paste


Login or Register to edit or fork this paste. It's free.