Hi all… i thought this would be relatively simple but alas!
i have a parent movieclip which houses a movieclip which has a scrollrect applied… i load images into the scrollrect and then in my document class on resize am trying to center the conainter movieclip with the scrollrect inside…
unfortunately the holder clip of the scrollRect gets a width equal to the width of all the images etc so i can’t use it as a basis for scaling…
has anyone else encountered this or know of a fix…
see code below! ARG!
My Parent and scrollRect MovieClip
public function CollectionImageScroller(imageArray:Array)
{
collectionImageScrollRect = new MovieClip();
collectionImageScrollRect.scrollRect = new Rectangle(0, 0, 0, 0);
collectionImagePathArrayFromXmlLoad = imageArray;
if(collectionImagePathArrayFromXmlLoad.length > 0)
{
collectionImages = new Array();
loadCollectionImage(collectionImagePathArrayFromXmlLoad[0]);
}
else
{
//display no images
}
}
function loadCollectionImage(imageUrl:String):void {
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, showLoading);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, initListener);
loader.load(new URLRequest("http://jademichelle.tom.test" + imageUrl));
}
function showLoading(e:Event):void
{
removeEventListener(Event.INIT, showLoading);
loaderIcon = new mcLoaderIcon();
addChild(loaderIcon);
}
function initListener(event:Event):void {
removeChild(loaderIcon);
var currentImage:DisplayObject = loader.content;
maxImageWidth = (maxImageWidth > currentImage.width) ? maxImageWidth : currentImage.width;
maxImageHeight = (maxImageHeight > currentImage.height) ? maxImageHeight : currentImage.height;
currentImage.x = currentImageX;
collectionImageScrollRect.addChild(currentImage);
currentImageX = currentImageX + currentImage.width + 5;
p++;
collectionImages.push(currentImage);
if (p < collectionImagePathArrayFromXmlLoad.length) {
loadCollectionImage(collectionImagePathArrayFromXmlLoad[p]);//create loop
}
if (p == collectionImagePathArrayFromXmlLoad.length) {
//do when done
this.graphics.drawRect(0,0, maxImageWidth, maxImageHeight);
collectionImageScrollRect.scrollRect = new Rectangle(0, 0, (maxImageWidth + 30), maxImageHeight);
addChild(collectionImageScrollRect);
var leftGradBorder:MovieClip = new mcGradBorder();
leftGradBorder.x = -5;
leftGradBorder.height = (maxImageHeight + 5);
addChild(leftGradBorder);
var rightGradBorder:MovieClip = new mcGradBorderRight();
rightGradBorder.x = maxImageWidth - 20;
rightGradBorder.height = (maxImageHeight + 5);
addChild(rightGradBorder);
collectionImageScrollRect.addEventListener(MouseEvent.CLICK, scrollMe);
dispatchEvent(new Event("CollectionImagesLoaded", true, false));
p=0;
}
}
function scrollMe(e:MouseEvent):void
{
rect = collectionImageScrollRect.scrollRect;
trace("rectx" + rect.x + "currentimgindex" + currentImageIndex);
TweenLite.to(rect, 1, {x:(rect.x + collectionImages[currentImageIndex].width + 5),onUpdate:updateScrollRect, onComplete:function() { currentImageIndex++; }});
}
function updateScrollRect()
{
collectionImageScrollRect.scrollRect = rect;
}
My Document Class handling scaling:
function setBackground():void {
if(collectionScroller != null)
{
collectionScroller.width = stage.stageWidth / 3;
collectionScroller.height = stage.stageHeight / 3;
collectionScroller.scaleX <= collectionScroller.scaleY ? (collectionScroller.scaleX = collectionScroller.scaleY) : (collectionScroller.scaleY = collectionScroller.scaleX);
collectionScroller.x = stage.stageWidth / 2 - (collectionScroller.width / 2);
collectionScroller.y = 100;
trace(collectionScroller.CalculatedWidth);
}
}
function positionCollectionImages(e:Event):void
{
removeEventListener("CollectionImagesLoaded", positionCollectionImages);
trace("MOOOOO");
trace("CALCULATED WIDTH " + collectionScroller.CalculatedWidth + " collectionscrollerx" + collectionScroller.x + " collectionscrollerwidth" + collectionScroller.width + " maximagewidth" + collectionScroller.MaxImageWidth);
collectionScroller.x = (stage.stageWidth / 2) - (collectionScroller.CalculatedWidth / 2);
collectionScroller.alpha = 1;
collectionScroller.visible = true;
//TweenLite.to(collectionScroller,1,{alpha:1});
setBackground();
}