marilynn.fowler
08-11-2008, 11:35 PM
I have a photo gallery. On the mainstage I've placed a movie clip that is populated via XML with thumbnails. I have left and right arrows that allow it to scroll, but I'm having trouble formulating the maximum scroll.
This is the code on the movie clip:
import fl.transitions.Tween;
import fl.transitions.easing.*;
var imageLoader:Loader;
var xml:XML;
var xmlList:XMLList;
var bigPhoto;
var fadeTween:Tween;
var thumbSpace:Number = 61;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("data/images.xml"));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
function xmlLoaded(event:Event):void {
xml = XML(event.target.data);
xmlList = xml.children();
for(var i:int = 0; i < xmlList.length(); i++) {
imageLoader = new Loader();
imageLoader.load(new URLRequest(xmlList[i].attribute("thumb")));
imageLoader.x = (i * thumbSpace);
imageLoader.y = 0;
imageLoader.name = xmlList[i].attribute("source");
addChild(imageLoader);
imageLoader.addEventListener(MouseEvent.CLICK, showPhoto);
}
}
function showPhoto(event:MouseEvent):void {
/*this works as well
MovieClip(root).photoGallery.source = event.target.name;
*/
(root as MovieClip).photoGallery.load(new URLRequest(event.target.name));
fadeTween = new Tween((root as MovieClip).photoGallery, "alpha", None.easeNone, 0, 1, 1, true);
}
This is the code on the main stage ( I put question marks on the line I can't figure:
stop();
var minScroll:Number = thumbs_mc.x;
var maxScroll:Number = ?????????????;
var targetScroll:Number = thumbs_mc.x;
var scrollAmt:Number = 15;
var scrollDirection:Number = 0;
var easing:Number = 4;
function scrollLeft(event:MouseEvent):void {
setDirection(-scrollAmt);
}
function scrollRight(event:MouseEvent):void {
setDirection(scrollAmt);
}
function setDirection(dir:Number):void {
//thumbs_mc.x += dir;
scrollDirection = dir;
stage.addEventListener(Event.ENTER_FRAME, scrollThumbs);
stage.addEventListener(MouseEvent.MOUSE_OUT, stopScrolling);
}
function scrollThumbs(event:Event):void {
targetScroll += scrollDirection;
thumbs_mc.x -=(thumbs_mc.x - targetScroll) / easing;
if (thumbs_mc.x > minScroll) {
thumbs_mc.x = minScroll;
targetScroll = minScroll;
}
else if(thumbs_mc.x < maxScroll) {
thumbs_mc.x = maxScroll;
targetScroll = maxScroll;
}
}
function stopScrolling(event:MouseEvent):void {
scrollDirection = 0;
}
left_btn.addEventListener(MouseEvent.MOUSE_OVER, scrollLeft);
right_btn.addEventListener(MouseEvent.MOUSE_OVER, scrollRight);
thumbs_mc.buttonMode = true;
Is there a way for it to assess the width of the populated movie clip on the fly? I think that I somehow need to get the xmlList.length and multiply it by the width of the thumbs (in this case 60), but my programming knowledge is limited and it seems that there ought to be a more efficient way.
This is the code on the movie clip:
import fl.transitions.Tween;
import fl.transitions.easing.*;
var imageLoader:Loader;
var xml:XML;
var xmlList:XMLList;
var bigPhoto;
var fadeTween:Tween;
var thumbSpace:Number = 61;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("data/images.xml"));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
function xmlLoaded(event:Event):void {
xml = XML(event.target.data);
xmlList = xml.children();
for(var i:int = 0; i < xmlList.length(); i++) {
imageLoader = new Loader();
imageLoader.load(new URLRequest(xmlList[i].attribute("thumb")));
imageLoader.x = (i * thumbSpace);
imageLoader.y = 0;
imageLoader.name = xmlList[i].attribute("source");
addChild(imageLoader);
imageLoader.addEventListener(MouseEvent.CLICK, showPhoto);
}
}
function showPhoto(event:MouseEvent):void {
/*this works as well
MovieClip(root).photoGallery.source = event.target.name;
*/
(root as MovieClip).photoGallery.load(new URLRequest(event.target.name));
fadeTween = new Tween((root as MovieClip).photoGallery, "alpha", None.easeNone, 0, 1, 1, true);
}
This is the code on the main stage ( I put question marks on the line I can't figure:
stop();
var minScroll:Number = thumbs_mc.x;
var maxScroll:Number = ?????????????;
var targetScroll:Number = thumbs_mc.x;
var scrollAmt:Number = 15;
var scrollDirection:Number = 0;
var easing:Number = 4;
function scrollLeft(event:MouseEvent):void {
setDirection(-scrollAmt);
}
function scrollRight(event:MouseEvent):void {
setDirection(scrollAmt);
}
function setDirection(dir:Number):void {
//thumbs_mc.x += dir;
scrollDirection = dir;
stage.addEventListener(Event.ENTER_FRAME, scrollThumbs);
stage.addEventListener(MouseEvent.MOUSE_OUT, stopScrolling);
}
function scrollThumbs(event:Event):void {
targetScroll += scrollDirection;
thumbs_mc.x -=(thumbs_mc.x - targetScroll) / easing;
if (thumbs_mc.x > minScroll) {
thumbs_mc.x = minScroll;
targetScroll = minScroll;
}
else if(thumbs_mc.x < maxScroll) {
thumbs_mc.x = maxScroll;
targetScroll = maxScroll;
}
}
function stopScrolling(event:MouseEvent):void {
scrollDirection = 0;
}
left_btn.addEventListener(MouseEvent.MOUSE_OVER, scrollLeft);
right_btn.addEventListener(MouseEvent.MOUSE_OVER, scrollRight);
thumbs_mc.buttonMode = true;
Is there a way for it to assess the width of the populated movie clip on the fly? I think that I somehow need to get the xmlList.length and multiply it by the width of the thumbs (in this case 60), but my programming knowledge is limited and it seems that there ought to be a more efficient way.