AS3 image gallery grid scroillbar

For the following link ( the code below works perfect except I want to dynamically decide if the scrollbar needs to appear or not.

If the user uses 8 or less images, no scrollbar is needed. If there are more, it needs to be shown. I have a movieClip that has a tinted movieClip inside. When I make the height 1000, then the scrollbars appear. When I make it 100, they do not. This is fine, but I want to make the height change dynamically. I have a function at the bottom called "determineHeightOfBkgd". this updates the tinted movieClip size, dynamically, but somehow the movieClip whose height changes doesn't afffect the scrollbars. If I set the tinted movieClip height to 1000 and the publich, the scrollbars still think the height of the movieCLip hasn't changed, even though I dynamically changed the height.

Am I missing a step or is there a function that will force the stage to update? Using updateAfterEvent?It is either wrong or I am not using it correctly.
import fl.containers.UILoader;
import caurina.transitions.*;

//---------loading the external xml file-------
var urlRequest:URLRequest = new URLRequest("pics.xml");
var urlLoader:URLLoader = new URLLoader();
var myXML:XML = new XML();
var xmlList:XMLList;
myXML.ignoreWhitespace = true;
//--------holds the paths to the thumbnails-------
var arrayURL:Array = new Array();
//--------holds the paths to the big photos-------
var arrayName:Array = new Array();
//--------holds the thumbnail objects-------
var holderArray:Array = new Array();
//--------represents the number of columns-------
var nrColumns:uint = 4;// 5
//-------represents the container of our gallery
var sprite:Sprite = new Sprite();
var thumb:Thumbnail;
//-------- the thumbnails container-------
var thumbsHolder:Sprite = new Sprite();
//-------- the photoLoader container-------
var loaderHolder:Sprite = new Sprite();,1);,0,350,230);//,0,550,330);;
loaderHolder.x = 1000;// this needs to be way off the stage, thus the 1000 location
loaderHolder.y = 10;
//-------- loads the big photo-------
var photoLoader:UILoader = new UILoader();
photoLoader.width = 340;// 540
photoLoader.height = 220;// 320
photoLoader.y = 0;//5
photoLoader.x = 0;//5
photoLoader.buttonMode = true;
//-------- static vars-------
var thumbHeight:uint = 110;

//-------- loads the big photo-------
/* we loop through the xml file
populate the arrayURL, arrayName and position the thumbnails*/
function fileLoaded(event:Event):void {
	myXML = XML(;
	xmlList = myXML.children();
	var myBkgdHeight:uint = determineHeightOfBkgd();
	trace("myBkgdHeight: " + myBkgdHeight);

	bkgdTint.height = myBkgdHeight;

	for (var i:int=0; i<xmlList.length(); i++) {
		var picURL:String = xmlList[i].url;
		var picName:String = xmlList[i].big_url;
		holderArray[i] = new Thumbnail(arrayURL[i],i,arrayName[i]);
		holderArray[i].name = arrayName[i];
		holderArray[i].buttonMode = true;
		if (i<nrColumns) {
			holderArray[i].y = 65;
			holderArray[i].x = i*thumbHeight+65;
		} else {
			holderArray[i].y = holderArray[i-nrColumns].y+thumbHeight;
			holderArray[i].x = holderArray[i-nrColumns].x;
//----handles the Click event added to the thumbnails--
function onClick(event:MouseEvent):void {
	photoLoader.source =;
	Tweener.addTween(thumbsHolder, {x:-650, time:1, transition:"easeInElastic"});
	Tweener.addTween(loaderHolder, {x:10, time:1, transition:"easeInElastic"});
	Tweener.addTween(thumbsHolder, {alpha:0, time:1, transition:"linear"});
	Tweener.addTween(loaderHolder, {alpha:1, time:1, transition:"linear"});
//----handles the Click event added to the photoLoader----
function onClickBack(event:MouseEvent):void {
	Tweener.addTween(thumbsHolder, {x:0, time:1, transition:"easeInElastic"});
	Tweener.addTween(loaderHolder, {x:1000, time:1, transition:"easeInElastic"});
	Tweener.addTween(thumbsHolder, {alpha:1, time:2, transition:"linear"});
	Tweener.addTween(loaderHolder, {alpha:0, time:2, transition:"linear"});
function determineHeightOfBkgd():uint {
	trace("xmlList.length: " + xmlList.length());
	trace("height: " + bkgdTint.height);
	var myHeight:uint;
	myHeight = ((xmlList.length()/4) * thumbHeight);
	return myHeight;

Open in new window

Who is Participating?
Try changing this line:
myHeight = ((xmlList.length()/4) * thumbHeight);

To this:
myHeight = (int(xmlList.length/4) * thumbHeight);

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.