Return to Snippet

Revision: 14872
at June 15, 2009 16:12 by Winkyboy


Initial Code
import caurina.transitions.Tweener; // don't forget to install this.

function loadImageTo(which_mc:MovieClip, whichImg:String, finishFunction:Function):void // syntax: loadImageTo("which movieclip to add the image to", "the path/URL to the image", "the function to call when complete")
{
	var imageLoader:Loader = new Loader();
	imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishFunction);
	which_mc.addChild(imageLoader);
	try {
		imageLoader.load(new URLRequest(whichImg));
	} catch (error:IOErrorEvent) {
		// ouch! an error
	} catch (error:Error) {
		// ouch! an error
	}
}

function hideSpinner1(e):void // you should totally customize this function
{
	Tweener.addTween(spinner_mc, {alpha:0, time:.5, onComplete:function(){ spinner_mc.enabled = false; } }); // keep this line in here, to hide the spinner.

	// resize your new image:
	holder_mc.width = stage.stageWidth;
	holder_mc.height = stage.stageHeight;
	
	// apply smoothing to your new image:
	var img_bm:Bitmap = new Bitmap();
	img_bm = Bitmap(e.currentTarget.content);
	img_bm.smoothing = true;	
}

function init()
{
	if (holder_mc.numChildren > 0) holder_mc.removeChildAt(0); // this line is added so that any previously-loaded image is removed before adding another to the holder
	loadImageTo(holder_mc, "sample.jpg", hideSpinner1); // if you want to use the loadImageTo function without a preloader spinner, just create an empty function and send that as the "finishFunction"
}

init(); // make it so.

Initial URL
http://dl.dropbox.com/u/316550/code-AS3-imgLoder.zip

Initial Description
Not a really elegant design, but it lets you mess around with the loading code easily.

Initial Title
AS3 Image Loader with circular preloader spinner

Initial Tags

                                

Initial Language
ActionScript 3