ImageGrid

Kind of class: public class
Package:
Inherits from:
  • Sprite
Known subclasses:
Version: 7 Mar 2010
Author: John Polacek, john@johnpolacek.com
Classpath: com.johnpolacek.components.ImageGrid
File last modified: Thursday, 24 February 2011, 22:09:57
Loads and arranges images in a grid NOTE: Images should be uniform in size.
Example

  • Create grid 4 images wide (images should be same size) var grid:ImageGrid = new ImageGrid(4); create grid 4 images wide x 3 images high var grid:ImageGrid = new ImageGrid(4, 3); create 4x3 grid, with 10 pixels spacing var grid:ImageGrid = new ImageGrid(4, 3, 10); create array of image url's
    var images = ["img/image1.jpg","img/image2.jpg"...]; // array of image url's
    grid.loadImages(images);
    

Summary

Constructor
Instance properties
  • gridWidth : int
    • Width of grid (i.e.
  • gridHeight : int
    • Height of grid (i.e.
  • spacing : int
    • Spacing between images (in pixels)
  • rows
    • Multidimensional array of images divided into rows
  • cols
    • Multidimensional array of images divided into columns
  • xCount : int
    • Tracks horizontal positioning during image loading
  • yCount : int
    • Tracks vertical positioning during image loading
  • urlsToLoad
    • Array of image url's being loaded
  • imagesLoaded : int
    • Number of images loaded
  • totalImages : int
    • Total number of images for the grid
  • transitionDuration : Number
    • Duration of fade transition in when images are loaded.
  • alignCenter : Boolean
    • If true, grid is aligned to the center
Instance methods
  • loadImages (urls:Array) : void
    • Loads multiple images into the grid
  • loadImage (url:String) : void
    • Loads a single image into the grid
  • addImage (image:Sprite) : void
    • Adds a sprite into the grid (at the last position)
  • onIOError (event:IOErrorEvent) : void
    • IOError handler
  • onImageLoadComplete (event:Event) : void
    • Image load complete handler

Constructor

ImageGrid

function ImageGrid(w:int, h:int, s:int)
Parameters
 

Instance properties

alignCenter

alignCenter:Boolean = false(read,write)

If true, grid is aligned to the center

cols

cols = [](read,write)

Multidimensional array of images divided into columns

gridHeight

gridHeight:int(read,write)

Height of grid (i.e. 4 images wide)

gridWidth

gridWidth:int(read,write)

Width of grid (i.e. 4 images wide)

imagesLoaded

imagesLoaded:int(read,write)

Number of images loaded

rows

rows = [](read,write)

Multidimensional array of images divided into rows

spacing

spacing:int(read,write)

Spacing between images (in pixels)

totalImages

totalImages:int(read,write)

Total number of images for the grid

transitionDuration

transitionDuration:Number(read,write)

Duration of fade transition in when images are loaded. Default is 0 (no transition).

urlsToLoad

urlsToLoad = [](read,write)

Array of image url's being loaded

xCount

xCount:int(read,write)

Tracks horizontal positioning during image loading

yCount

yCount:int(read,write)

Tracks vertical positioning during image loading

Instance methods

addImage

function addImage(image:Sprite) : void

Adds a sprite into the grid (at the last position)

Parameters
url:Image URL string to load

loadImage

function loadImage(url:String) : void

Loads a single image into the grid

Parameters
url:Image URL string to load

loadImages

function loadImages(urls:Array) : void

Loads multiple images into the grid

Parameters
urls:Array of image URL strings to load

onIOError

function onIOError(event:IOErrorEvent) : void

IOError handler

onImageLoadComplete

function onImageLoadComplete(event:Event) : void

Image load complete handler