Problem with application of a mask [AS 3.0]

Hi! it’s the first time i write in this forum, but always noticed the high skill level in here .)

i apologize for my robotic english, i normally speak italian!

i’m recently creating a dynamic gallery who is loaded in a site structure:

the pages are created and loaded in a “pageID” position of a “sitePages” array…
when a page is called, the pageBox is faded out, the “previous page” child is removed and the “new page” child is loaded, and the page is shown fading in the pageBox… simple!

Some “listed item pages”, and the galleries are masked containers, scrolled up and down (or left and right) with two simple buttons…

MY PROBLEM:

if i load 2 or 3 items in the gallery container, or in the item container, the mask works fine, and everything looks as i programmed it… but if i load a larger amount of pictures or items in the containers, the container looks being not masked!

how is it possible? is it a “time gap” problem between the end of the pictures load and the mask instruction or what else? i can’t think this is possible, because i checked the instructions priority diagram, and everything looks allright…

i checked the internet for this problem, but i didn’t find any post/article/news about this problem but nothing has appeared…

i add some code for the braves who will help this poor programmer with his problem :frowning:


function gotoGallery(galleryID:Number):void
{
	requestedGID = galleryID;
	
	if (galleryCheck[galleryID] == null)
		{
			this.addChild(loader);
			loader.alpha = 1;
			buildGallery(galleryID);
			showGallery(galleryID);
			galleryCheck[galleryID] = "OK";
			
			currentGID = galleryID;

			trace("! --- Gallery "+galleryID+" has been created and displayed");
		}
		
		else
		{
			showGallery(galleryID);
			
			currentGID = galleryID;
			
			trace("! --- Gallery "+galleryID+" has been displayed");
		}
}

function buildGallery(galleryID:Number):void
{
	
	trace("! --- Function buildGallery(galleryID) has been called!");
	
	if(currentID == 0)
	{
		var page0:MovieClip = new MovieClip();
		sitePages[0] = page0;
		pageBox.addChild(sitePages[0]);
	}
	
	var page:MovieClip = new MovieClip;
		page.x = 60;
		page.y = 140;
		
	var galleryXML:XML = new XML(galleriesXML.gallery.(@ID == galleryID));

	var titleG:TextField = new TextField();
		titleG.wordWrap = true;
		titleG.selectable = false;
		titleG.embedFonts = true;
		titleG.antiAliasType = "advanced"
		titleG.alpha = 0.25;
			
	var txtG1:TextField = new TextField();
		txtG1.wordWrap = true;
		txtG1.selectable = false;
		txtG1.multiline = true;
		txtG1.autoSize = TextFieldAutoSize.LEFT;
		txtG1.embedFonts = true;
		txtG1.antiAliasType = "advanced";
		
	titleG.x = txtG1.x = 35;
	titleG.y = 30;
	txtG1.y = 70;
	titleG.height = txtG1.height = 30;
	titleG.width =  txtG1.width = 600;

	titleG.text = galleryXML.@title;
	txtG1.text = galleryXML.txt.text();
	titleG.setTextFormat(titleTF);
	txtG1.setTextFormat(textTF);
			
	var gi:Number;
	var picNumG:Number = galleryXML.picture.length();
	var picIDG:Number = 0;
	var galleryIndex:Number = galleryID*100;
	
	galleryItems[galleryID] = picNumG;
	
	var btnLeftG:ArrowBTN = new ArrowBTN();
		btnLeftG.rotation = 270;
		btnLeftG.buttonMode = true;
			
		btnLeftG.addEventListener(MouseEvent.MOUSE_DOWN, galleryContRight);
				
	var btnRightG:ArrowBTN = new ArrowBTN();
		btnRightG.rotation = 90;
		btnRightG.buttonMode = true;
		
		btnRightG.addEventListener(MouseEvent.MOUSE_DOWN, galleryContLeft);
					
	btnLeftG.x = 60; btnLeftG.y = 265;
	btnRightG.x = 740; btnRightG.y = 235;
			
	page.addChild(titleG);
	page.addChild(txtG1);
	page.addChild(btnLeftG);
	page.addChild(btnRightG);
			
	siteGalleries[galleryID] = page;
	
	for(gi=0;gi<picNumG;gi++)
	{
		picIDG++;
		var picURLG:String = galleryXML.picture[gi].@url;
		
		var picIndex:Number = galleryIndex+picIDG;
		
		picsIndexList.push(picIndex);
				
		galleryPicLoaders[picIndex] = new Loader();
		galleryPicLoaders[picIndex].load(new URLRequest(picURLG));
		galleryPicLoaders[picIndex].contentLoaderInfo.addEventListener(Event.COMPLETE, picLoaded);
	}
}

function picLoaded(evt:Event):void
{
	galleryPicsLoaded++;
			
	checkAndDraw();
}

		
function checkAndDraw():void
{
	trace("! --- function checkAndDraw() has been called!");
	var i:Number;
	var galleryID:Number = requestedGID;
	var galleryContG:MovieClip = new MovieClip();
	var totalPics:Number = galleryItems[galleryID];
	var picSpaceG:Number = 60;
	
	var maskerG:GMasker = new GMasker();
	
	if(galleryPicsLoaded == totalPics)
	{
		for(i=0;i<totalPics;i++)
		{
			pageBox.addChild(loader);
			var index:Number = picsIndexList*;
				
			galleryPicBitmaps[index] = Bitmap(galleryPicLoaders[index].content);
			
			var picG:Bitmap = galleryPicBitmaps[index];
			var picGW:Number = picG.width;
			var picGH:Number = picG.height;
			
			var picGScale:Number = 1;
			trace(picG.width);
			
			if(picGW > 560)
			{
				picGScale = 560/picGW;
			}

			if(picGH > 280)
			{
				picGScale = 280/picGH;
			}
									
			picG.scaleX = picGScale;
			picG.scaleY = picGScale;
			picG.smoothing = true;
			
			var squareGW:Number = picG.width;
			var squareGH:Number = picG.height;
			
			var picSquareG:Sprite = new Sprite();
			var picMaskG:Sprite = new Sprite();
			var picContG:Sprite = new Sprite();
		
			var psquareGrG:Graphics = picSquareG.graphics;
				psquareGrG.lineStyle(1.5, 0xFFF290);
				psquareGrG.beginFill(0x000000);
				psquareGrG.drawRect(0, 0, squareGW, squareGH);
				psquareGrG.endFill();
			
			var pmaskGrG:Graphics = picMaskG.graphics;
				pmaskGrG.beginFill(0xFFFFFF);
				pmaskGrG.drawRect(0, 0, squareGW, squareGH);
				pmaskGrG.endFill();
				
				picSquareG.x += (560-squareGW)/2;
				picMaskG.x += (560-squareGW)/2;
				picG.x += (560-squareGW)/2;
				
				picSquareG.y += (280-squareGH)/2;
				picMaskG.y += (280-squareGH)/2;
				picG.y += (280-squareGH)/2;
				
			picContG.addChild(picSquareG);
			picContG.addChild(picMaskG);
			picContG.addChild(picG);
		
			picContG.x = picSpaceG; picContG.y = 105;
			picSpaceG += 700;
			
			galleryContG.addChild(picContG); 
		}
	 
		for(i=0;i<totalPics;i++)
		{	
			var clearindex:Number = picsIndexList*;
			
			galleryPicLoaders[clearindex].contentLoaderInfo.removeEventListener(Event.COMPLETE, picLoaded);
			galleryPicLoaders[clearindex] = null; 
		}
	   
		galleryPicLoaders = [];
		picsIndexList = [];
		
		galleryContG.x = 60; galleryContG.y = 10;
		
		maskerG.x = 90; maskerG.y = 60;
						
		maskerG.cacheAsBitmap = true;
		galleryContG.cacheAsBitmap = true;

		galleryContG.mask = maskerG;
		
		siteGalleries[galleryID].addChild(galleryContG);
		siteGalleries[galleryID].addChild(maskerG);
			
		galleryContainers[galleryID] = galleryContG;
		galleryStepCounter[galleryID] = 0;
		galleryPicsLoaded = 0;	
		pageBox.removeChild(loader);
	}
}


function showGallery(galleryID:Number):void
{
	trace("! --- function showPage(pageID:Number) has been called!");
	
	tweenArray[tweenCount] = new Tween(pageBox, "alpha", Regular.easeOut, 1, 0, 5, false);
	tweenArray[tweenCount].addEventListener(TweenEvent.MOTION_FINISH, galleryFadeIn);
	tweenArray[tweenCount].addEventListener(TweenEvent.MOTION_FINISH, removeLoader);
	tweenCount++;
}


function galleryFadeIn(evt:TweenEvent)
{	
	var nextPage:MovieClip = siteGalleries[requestedGID];
	
	pageBox.removeChildAt(0);
	
	pageBox.addChildAt(nextPage, 0);
	
	tweenArray[tweenCount] = new Tween(pageBox, "y", Back.easeOut, 40, 0, 14, false);
	tweenCount++;
	tweenArray[tweenCount] = new Tween(pageBox, "alpha", Regular.easeIn, 0, 1, 14, false);
	tweenCount++;
}

function galleryContLeft(evt:MouseEvent)
{	
	var stepCount:Number = galleryStepCounter[currentGID];
	var galleryContainer:MovieClip = galleryContainers[currentGID];
	
	contSteps = galleryItems[currentGID]-1;
	
	if(stepCount >= contSteps)
	{
		return;
	}
	
	stepCount++;
	
	trace(contSteps);
	trace(stepCount);

	tweenArray[tweenCount] = new Tween(galleryContainer, "x", Regular.easeOut, 760+(700*-stepCount), 60+(700*-stepCount), 16, false);
	tweenCount++;
	
	galleryStepCounter[currentGID] = stepCount;
}

function galleryContRight(evt:MouseEvent)
{	
	var stepCount:Number = galleryStepCounter[currentGID];
	var galleryContainer:MovieClip = galleryContainers[currentGID];
	
	if(stepCount == 0)
	{
		return;
	}
	
	trace(contSteps);
	trace(stepCount);
	
	tweenArray[tweenCount] = new Tween(galleryContainer, "x", Regular.easeOut, 60-(700*stepCount), 760-(700*stepCount), 16, false);
	tweenCount++;
	stepCount--;
	
	galleryStepCounter[currentGID] = stepCount;
}


If you don’t believe me i can give you a link to the site “test page” :stuck_out_tongue: but, please believe me, i’m not joking!

If someone have an idea of what’s happening, please contact me, i’m going crazy!

Thanks! e.