/** * VERSION: 1.84 * DATE: 2011-03-23 * AS3 * UPDATES AND DOCS AT: http://www.greensock.com/loadermax/ **/ package com.greensock.loading { import com.greensock.loading.core.DisplayObjectLoader; import flash.display.Bitmap; import flash.events.Event; /** * Loads an image file (png, jpg, or gif) and automatically applies smoothing by default.

* * The ImageLoader's content refers to a ContentDisplay (Sprite) that * is created immediately so that you can position/scale/rotate it or add ROLL_OVER/ROLL_OUT/CLICK listeners * before (or while) the image loads. Use the ImageLoader's content property to get the ContentDisplay * Sprite, or use the rawContent property to get the actual Bitmap. If a container * is defined in the vars object, the ContentDisplay will immediately be added to that container).

* * If you define a width and height, it will draw a rectangle * in the ContentDisplay so that interactive events fire appropriately (rollovers, etc.) and width/height/bounds * get reported accurately. This rectangle is invisible by default, but you can control its color and alpha * with the bgColor and bgAlpha properties. When the image loads, it will be * added to the ContentDisplay at index 0 with addChildAt() and scaled to fit the width/height * according to the scaleMode. These are all optional features - you do not need to define a * width or height in which case the image will load at its native size. * See the list below for all the special properties that can be passed through the vars * parameter but don't let the list overwhelm you - these are all optional and they are intended to make * your job as a developer much easier.

* * By default, the ImageLoader will attempt to load the image in a way that allows full script * access. However, if a security error is thrown because the image is being loaded from another * domain and the appropriate crossdomain.xml file isn't in place to grant access, the ImageLoader * will automatically adjust the default LoaderContext so that it falls back to the more restricted * mode which will have the following effect: * * * To maximize the likelihood of your image loading without any security problems, consider taking the following steps: *
* * OPTIONAL VARS PROPERTIES
* The following special properties can be passed into the ImageLoader constructor via its vars * parameter which can be either a generic object or an ImageLoaderVars object:
*
* * Note: Using a ImageLoaderVars instance * instead of a generic object to define your vars is a bit more verbose but provides * code hinting and improved debugging because it enforces strict data typing. Use whichever one you prefer.

* * Jerky animation? If you animate the image after loading it and you notice that the movement * is rather jerky, try setting the scaleX and/or scaleY to something other than 1, like 1.001 because there is * a bug in Flash that forces Bitmaps to always act like their pixelSnapping is "auto" * when their scaleX/scaleY are 1.

* * content data type: com.greensock.loading.display.ContentDisplay (a Sprite). * When the image has finished loading, the rawContent will be added to the ContentDisplay Sprite * at index 0 using addChildAt(). rawContent will be a flash.display.Bitmap unless * unless script access is denied in which case it will be a flash.display.Loader (to avoid security errors).

* * @example Example AS3 code: import com.greensock.~~; import com.greensock.events.LoaderEvent; import com.greensock.loading.~~; //create an ImageLoader: var loader:ImageLoader = new ImageLoader("img/photo1.jpg", {name:"photo1", container:this, x:180, y:100, width:200, height:150, scaleMode:"proportionalInside", centerRegistration:true, onComplete:onImageLoad}); //begin loading loader.load(); //when the image loads, fade it in from alpha:0 using TweenLite function onImageLoad(event:LoaderEvent):void { TweenLite.from(event.target.content, 1, {alpha:0}); } //Or you could put the ImageLoader into a LoaderMax. Create one first... var queue:LoaderMax = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler}); //append the ImageLoader and several other loaders queue.append( loader ); queue.append( new XMLLoader("xml/doc.xml", {name:"xmlDoc", estimatedBytes:425}) ); queue.append( new SWFLoader("swf/main.swf", {name:"mainClip", estimatedBytes:3000, container:this, autoPlay:false}) ); //start loading queue.load(); function progressHandler(event:LoaderEvent):void { trace("progress: " + queue.progress); } function completeHandler(event:LoaderEvent):void { trace(event.target + " is complete!"); } function errorHandler(event:LoaderEvent):void { trace("error occured with " + event.target + ": " + event.text); } * NOTES / TIPS:
*

* * Copyright 2011, GreenSock. All rights reserved. This work is subject to the terms in http://www.greensock.com/terms_of_use.html or for corporate Club GreenSock members, the software agreement that was issued with the corporate membership. * * @see com.greensock.loading.data.ImageLoaderVars * * @author Jack Doyle, jack@greensock.com */ public class ImageLoader extends DisplayObjectLoader { /** @private **/ private static var _classActivated:Boolean = _activateClass("ImageLoader", ImageLoader, "jpg,jpeg,png,gif,bmp"); /** * Constructor * * @param urlOrRequest The url (String) or URLRequest from which the loader should get its content * @param vars An object containing optional configuration details. For example: new ImageLoader("img/photo1.jpg", {name:"photo1", container:this, x:100, y:50, alpha:0, onComplete:completeHandler, onProgress:progressHandler}).

* * The following special properties can be passed into the constructor via the vars parameter * which can be either a generic object or an ImageLoaderVars object:
* * @see com.greensock.loading.data.ImageLoaderVars */ public function ImageLoader(urlOrRequest:*, vars:Object=null) { super(urlOrRequest, vars); _type = "ImageLoader"; } //---- EVENT HANDLERS ------------------------------------------------------------------------------------ /** @private **/ override protected function _initHandler(event:Event):void { _determineScriptAccess(); if (!_scriptAccessDenied) { _content = Bitmap(_loader.content); _content.smoothing = Boolean(this.vars.smoothing != false); } else { _content = _loader; } super._initHandler(event); } } }