June 18, 2009

ActionScript 2 – Fullscreen Flash Gallery

Filed under: Flash — admin @ 11:14 pm

Download Source View Example

This code will create a grid of thumbnails that will display fullscreen – and the number of thumbnails changes dynamically based upon the size of the browser window. It works similar to thefwa. This example loads a series of Movie Clips with an ID assigned to each one. But this can easily be customized to use an XML file for loading gallery assets.

var stageListener:Object = new Object();
stageListener.onResize = function() {
	positionThumbs();
};
 
Stage.align = "TL";
Stage.scaleMode = "noScale";
Stage.addListener(stageListener);
 
function positionThumbs() {
 
	var W:Number = Stage.width;
	var H:Number = Stage.height;
	var t_total:Number = 99;
	var twidth:Number = 204;
	var theight:Number = 124;
	var tx:Number = 0;
	var ty:Number = 0;
	var rows:Number = Math.floor((t_total*twidth)/W);
	var pagination:Number = 0;
 
	for (var i:Number = 0; i<total; i++) {
		var t_mc:MovieClip = target_mc.attachMovie("thumb", "thumb_mc"+i, i);
		t_mc.ID = i;
		t_mc.title_txt.text = i;
		if (pagination<W-(twidth*2)) {
			if (i != 0) {
				pagination += twidth;
				tx += twidth;
			}
		} else {
			pagination = 0;
			tx = 0;
			if (i != 0) {
				ty += theight;
			}
		}
		t_mc._x = tx;
		t_mc._y = ty;
		t_mc.onRollOver = function() {
			this._alpha = 50;
		};
		t_mc.onRollOut = t_mc.onReleaseOutside = function() {
			this._alpha = 100;
		};
	}
}
 
positionThumbs();

View the example above and try to resize your browser window. You’ll see that the number of thumbnails dynamically change.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

© 2010 Aaron Benson. All rights reserved.

Powered by WordPress