/** * VERSION: 1.7 * DATE: 2010-11-13 * AS3 * UPDATES AND DOCS AT: http://www.greensock.com/loadermax/ **/ package com.greensock.loading { import com.greensock.loading.core.LoaderItem; import flash.display.DisplayObject; import flash.display.LoaderInfo; import flash.events.Event; import flash.events.ProgressEvent; /** * Tracks the loading progress of the swf in which the loader resides (basically a simple tool for tracking * the loaderInfo's progress). SelfLoader is only useful in situations where you want to factor * the current swf's loading progress into a LoaderMax queue or maybe display a progress bar for the current * swf or fire an event when loading has finished.

* * OPTIONAL VARS PROPERTIES
* The following special properties can be passed into the SelfLoader constructor via its vars parameter:
*
* * @example Example AS3 code: import com.greensock.loading.~~; import com.greensock.events.LoaderEvent; //create a SelfLoader var loader:SelfLoader = new SelfLoader(this, {name:"self", onProgress:progressHandler, onComplete:completeHandler}); //Or you could put the SelfLoader into a LoaderMax. Create one first... var queue:LoaderMax = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler}); //append the SelfLoader and several other loaders queue.append( loader ); queue.append( new ImageLoader("images/photo1.jpg", {name:"photo1", container:this}) ); queue.append( new SWFLoader("swf/child.swf", {name:"child", container:this, x:100, estimatedBytes:3500}) ); //start loading the LoaderMax queue queue.load(); function progressHandler(event:LoaderEvent):void { trace("progress: " + event.target.progress); } function completeHandler(event:LoaderEvent):void { trace(event.target + " complete"); } function errorHandler(event:LoaderEvent):void { trace("error occured with " + event.target + ": " + event.text); } * * 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. * * @author Jack Doyle, jack@greensock.com */ public class SelfLoader extends LoaderItem { /** @private **/ protected var _loaderInfo:LoaderInfo; /** * Constructor * * @param self A DisplayObject from the main swf (it will use this DisplayObject's loaderInfo to track the loading progress). * @param vars An object containing optional configuration details. For example: new SelfLoader(this, {name:"self", onComplete:completeHandler, onProgress:progressHandler}).

* * The following special properties can be passed into the constructor via the vars parameter:
* */ public function SelfLoader(self:DisplayObject, vars:Object=null) { super(self.loaderInfo.url, vars); _type = "SelfLoader"; _loaderInfo = self.loaderInfo; _loaderInfo.addEventListener(ProgressEvent.PROGRESS, _progressHandler, false, 0, true); _loaderInfo.addEventListener(Event.COMPLETE, _completeHandler, false, 0, true); _cachedBytesTotal = _loaderInfo.bytesTotal; _cachedBytesLoaded = _loaderInfo.bytesLoaded; _status = (_cachedBytesLoaded == _cachedBytesTotal) ? LoaderStatus.COMPLETED : LoaderStatus.LOADING; _auditedSize = true; _content = self; } /** @private scrubLevel: 0 = cancel, 1 = unload, 2 = dispose, 3 = flush **/ override protected function _dump(scrubLevel:int=0, newStatus:int=0, suppressEvents:Boolean=false):void { if (scrubLevel >= 2) { _loaderInfo.removeEventListener(ProgressEvent.PROGRESS, _progressHandler); _loaderInfo.removeEventListener(Event.COMPLETE, _completeHandler); } super._dump(scrubLevel, newStatus, suppressEvents); } } }