AS3 lightBox class

This is not ready but I would like to share it anyways, for two reasons: I couldn’t find a free class (or didn’t look hard enough) and someone else might be looking for it. And also so people can take a look at my code and point something that could be improved.

I will post the final version once it is ready.

LightBox.as

//AS3///////////////////////////////////////////////////////////////////////////
// 
//  FlashInit.com
// 
////////////////////////////////////////////////////////////////////////////////
 
package
{	
	/**
	 *  LightBox Class
	 *    
	 *  @langversion ActionScript 3
	 *  @playerversion Flash 9.0.0
	 *
	 *  @author Pedro Canterini
	 *  @since  22.04.2009
	 */
 
	import flash.display.Sprite;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	import flash.net.URLRequest;
 
	public class LightBox extends Sprite
	{
 
		//---------------------------------------
		// PRIVATE VARIABLES
		//---------------------------------------
		private var _imageHolder:Sprite;
		private var _loader:Loader;
 
		/**
		 *   @constructor
		 */
		public function LightBox(url:String)
		{
			trace("lightbox is on! load: ", url);
			var req:URLRequest = new URLRequest(url);
			_loader = new Loader();
			_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
			_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, handleProgress, false, 0, true);
			_loader.load(req);
		}
 
		//---------------------------------------
		// PUBLIC METHODS
		//---------------------------------------
		public function alignToCenter(object:DisplayObject):void
		{
			object.x = (object.stage.stageWidth - object.width) / 2;
			object.y = (object.stage.stageHeight - object.height) / 2;
		}
 
		//---------------------------------------
		// PRIVATE METHODS
		//---------------------------------------
		private function handleProgress(event:ProgressEvent):void
		{
			var percent:uint = int((event.bytesLoaded / event.bytesTotal) * 100);
			trace(percent);
		}
 
		private function onComplete(event:Event):void
		{
			_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete);
			handleImage();
		}
 
		private function handleImage():void
		{
			/* create holder for the bitmap */
			_imageHolder = new Sprite();
			addChild(_imageHolder);
			_imageHolder.addChild(_loader);
 
			/* align object */
			alignToCenter(_imageHolder);
		}
	}
}

in order to use it just create a new Instance of it:

var lightBox:LightBox = new LightBox("assets/imgs/retratos/img-001.jpg");
addChild(lightBox);

I am working on the background and a loader and I will post as soon as they are done and integrated.

  1. tom says:

    Post the final when you get a chance. I’d love to see a working demo.

  1. KYLE says:


    PillSpot.org. Canadian Health&Care.Best quality drugs.Special Internet Prices.No prescription online pharmacy. No prescription pills. Buy drugs online

    Buy:Wellbutrin SR.Cozaar.Seroquel.Female Cialis.Acomplia.Zetia.Nymphomax.Zocor.Lipothin.Female Pink Viagra.SleepWell.Lipitor.Aricept.Prozac.Buspar.Amoxicillin.Lasix.Benicar.Ventolin.Advair….

  2. MANUEL says:


    Medicamentspot.com. Canadian Health&Care.No prescription online pharmacy.Best quality drugs.Special Internet Prices. No prescription pills. Order pills online

    Buy:Zetia.Female Pink Viagra.Acomplia.Wellbutrin SR.SleepWell.Female Cialis.Ventolin.Amoxicillin.Seroquel.Lipitor.Lipothin.Prozac.Buspar.Lasix.Cozaar.Aricept.Zocor.Advair.Nymphomax.Benicar….

  3. CAMERON says:


    CheapTabletsOnline.com. Canadian Health&Care.No prescription online pharmacy.Best quality drugs.Special Internet Prices. Low price pills. Order pills online

    Buy:Cialis Professional.Super Active ED Pack.VPXL.Viagra Super Active+.Cialis.Viagra.Tramadol.Viagra Super Force.Propecia.Levitra.Viagra Professional.Zithromax.Cialis Super Active+.Cialis Soft Tabs.Maxaman.Viagra Soft Tabs.Soma….

Leave a Reply