Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    previous next buttons

    hi, i'm trying to add some previous and next buttons to a gallery flash file i modified. i'd like to add buttons to the right and left of the large images so the user can advance the images without having to use the thumbnail bar. any help would be appreciated. here's my current actionscript:

    Code:
    //set stage background color 
    myColor = new Color(bgColor);
    myColor.setRGB("0xffffff");
    bg._alpha=0;
    
    //The following is for general settings:
    _root.originThumbnailX = mc_thumbnail._x;
    var generalXML:XML = new XML();
    generalXML.ignoreWhite = true;
    generalXML.load("general.xml");
    generalXML.onLoad = loadGeneralXML;
    function loadGeneralXML(loaded) {
    	if (loaded) {
    		theRootNode = this.firstChild;
    		_root.largeImageEffect = theRootNode.childNodes[0].childNodes[0].nodeValue;
    		var backgroundImage:String = theRootNode.childNodes[1].childNodes[0].nodeValue;
    		if (backgroundImage.toUpperCase() == "ON") {
    			bg._alpha=100;
    		}
    		
    		var backgroundColor:String = theRootNode.childNodes[2].childNodes[0].nodeValue;
    		//set stage background color 
    		myColor = new Color(bgColor);
    		myColor.setRGB("0x"+backgroundColor);
    		
    		
    		
    		
    	}
    }
    // The following is for the categories:
    var myXML:XML = new XML();
    myXML.ignoreWhite = true;
    myXML.load("category.xml");
    myXML.onLoad = loadXML;
    var catBtns:Array = Array();
    function loadXML(loaded) {
    	if (loaded) {
    		rootNode = this.firstChild;
    		_root.numberOfItem = rootNode.firstChild.childNodes.length;
    		verticalDistance = rootNode.lastChild.childNodes[0].firstChild.nodeValue;
    		for (var i = 0; i<_root.numberOfItem; i++) {
    			menuList.categoryAll.m_category.btn.duplicateMovieClip("btn"+i, i);
    			_root.main.menuList.categoryAll.m_category["btn"+i].theText = rootNode.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue;
    			_root.main.menuList.categoryAll.m_category["btn"+i].theID = rootNode.firstChild.childNodes[i].childNodes[1].firstChild.nodeValue;
    			_root.main.menuList.categoryAll.m_category["btn"+i]._y = _root.main.menuList.categoryAll.m_category.btn0._y+(i*verticalDistance);
    			_root.main.menuList.categoryAll.m_category["btn"+i].btnNumber = i;
    			catBtns.push(_root.main.menuList.categoryAll.m_category["btn"+i]);
    		}
    		//catBtns[0].gotoAndStop("2");
    		_root.currentBtn = "";
    	}
    }
    function resetAllButtons() {
    	catBtns[_root.currentBtn].gotoAndPlay("1");
    }
    // The following is for the thumbnails and big image
    var myXML2:XML = new XML();
    myXML2.ignoreWhite = true;
    myXML2.load("gallery_bty.xml");
    var Name:Array = Array();
    var ImgWidth:Array = Array();
    var ImgHeight:Array = Array();
    var thumbPath:Array = Array();
    var picPath:Array = Array();
    var linkURL:Array = Array();
    _root.currentCatID = 1;
    _root.gapH = 7;
    // horizontal space
    myXML2.onLoad = function(success) {
    	displayPage();
    };
    function displayPage() {
    	mc_thumbnail._x = _root.originThumbnailX;
    	delete rightBtn.onEnterFrame;
    	delete leftBtn.onEnterFrame;
    	//remove existing thumbnails
    	for (var i = 0; i<_root.numberOfItems; i++) {
    		removeMovieClip(mc_thumbnail["img"+i]);
    	}
    	xml = myXML2.firstChild;
    	_root.numberOfItems = xml.childNodes.length;
    	_root.numberInCategory = 0;
    	var itemsInThisCat:Array = Array();
    	for (var i = 0; i<_root.numberOfItems; i++) {
    		if (xml.childNodes[i].childNodes[6].childNodes[0].nodeValue == _root.currentCatID) {
    			_root.numberInCategory++;
    			itemsInThisCat.push(i);
    		}
    	}
    	var numberOfImgs:Number = itemsInThisCat.length;
    	var integer:Number = Math.floor(numberOfImgs/7);
    	var remainder:Number = numberOfImgs%7;
    	var maxRightClickTime:Number = 0;
    	//if total imgs over 7
    	if (remainder == 0) {
    		maxRightClickTime = integer-1;
    	} else {
    		maxRightClickTime = integer;
    	}
    	var leftClickTime:Number = 0;
    	var rightClickTime:Number = 0;
    	var currentTarget:Number = 0;
    	leftBtn._visible = false;
    	//if total imgs less than 7 or equal 7
    	if (numberOfImgs<7) {
    		rightBtn._visible = false;
    	} else {
    		rightBtn._visible = true;
    	}
    	var originX:Number = mc_thumbnail._x;
    	currentTarget = 0;
    	rightBtn.onRelease = function() {
    		leftBtn._visible = true;
    		rightClickTime++;
    		if (rightClickTime == maxRightClickTime) {
    			rightBtn._visible = false;
    		}
    		currentTarget = originX-(mc_thumbnail.img._width+_root.gapH)*7*rightClickTime;
    		this.onEnterFrame = function() {
    			diff = currentTarget-mc_thumbnail._x;
    			mc_thumbnail._x += diff/4;
    		};
    	};
    		leftBtn.onRelease = function() {
    		rightBtn._visible = true;
    		rightClickTime--;
    		leftClickTime++;
    		if (rightClickTime == 0) {
    			leftBtn._visible = false;
    		}
    		currentTarget = originX-(mc_thumbnail.img._width+_root.gapH)*7*rightClickTime;
    		this.onEnterFrame = function() {
    			diff = currentTarget-mc_thumbnail._x;
    			mc_thumbnail._x += diff/4;
    		};
    	};
    	for (var i = 0; i<itemsInThisCat.length; i++) {
    		Name[i] = xml.childNodes[itemsInThisCat[i]].childNodes[0].childNodes[0].nodeValue;
    		ImgWidth[i] = xml.childNodes[itemsInThisCat[i]].childNodes[1].childNodes[0].nodeValue;
    		ImgHeight[i] = xml.childNodes[itemsInThisCat[i]].childNodes[2].childNodes[0].nodeValue;
    		thumbPath[i] = xml.childNodes[itemsInThisCat[i]].childNodes[3].childNodes[0].nodeValue;
    		picPath[i] = xml.childNodes[itemsInThisCat[i]].childNodes[4].childNodes[0].nodeValue;
    		linkURL[i] = xml.childNodes[itemsInThisCat[i]].childNodes[5].childNodes[0].nodeValue;
    		mc_thumbnail.img.duplicateMovieClip("img"+i, i);
    		mc_thumbnail["img"+i]._x = mc_thumbnail.img._x+i*(95+_root.gapH);
    		mc_thumbnail.img0._x = 0;
    		if (thumbPath[i] == "undefined") {
    			mc_thumbnail["img"+i].enabled = false;
    		} else {
    			mc_thumbnail["img"+i].enabled = true;
    			mc_thumbnail["img"+i].img_mc.loadMovie(thumbPath[i]);
    		}
    		mc_thumbnail["img"+i].theImageName = Name[i];
    		mc_thumbnail["img"+i].theLinkURL = linkURL[i];
    		mc_thumbnail["img"+i].thePicPath = picPath[i];
    		mc_thumbnail["img"+i].theWidth = ImgWidth[i];
    		mc_thumbnail["img"+i].theHeight = ImgHeight[i];
    	}
    	//load the first big image   
    	showLargeImg(ImgWidth[0], ImgHeight[0], picPath[0], linkURL[0], Name[0]);
    }
    function showLargeImg(theWidth:Number, theHeight:Number, thePicPath:String, theLinkURL:String, theImageName:String) {
    	_root.main.big_mc.big_mc_image.container._alpha = 0;
    	var theImageWidth:Number = theWidth;
    	theImageHeight = theHeight;
    	theDisplayAreaWidth = 735;
    	theDisplayAreaHeight = mask._y+7;
    	//trace(theDisplayAreaHeight+" "+mask._y);
    	_root.main.big_mc._x = (theDisplayAreaWidth-theImageWidth)/2;
    	_root.main.big_mc._y = (theDisplayAreaHeight-theImageHeight)/2;
    	_root.targetX = _root.main.big_mc._x-4;
    	_root.targetY = _root.main.big_mc._y-6;
    	_root.targetWidth = theImageWidth*1+7;
    	_root.targetHeight = theImageHeight*1+7;
    	_root.targetY2 = _root.targetY-txtImageTitle._height;
    	//define empty movieclip, my_mc and preloader object
    	var empty = _root.main.big_mc.big_mc_image.createEmptyMovieClip("container", "100");
    	_root.main.big_mc.big_mc_image.my_mc = new MovieClipLoader();
    	preload = new Object();
    	_root.main.big_mc.big_mc_image.my_mc.addListener(preload);
    	preload.onLoadComplete = function(targetMC) {
    		if (_root.largeImageEffect.toUpperCase() == "ON") {
    			_root.main.big_mc.big_mc_image.container._alpha = 100;
    		} else {
    			_root.main.big_mc.big_mc_image.container._alpha = 0;
    		}
    		changeColor();
    	};
    	_parent.onEnterFrame = function() {
    		diffX = _root.targetX-_root.main.mc_bigImageBg._x;
    		_root.main.mc_bigImageBg._x += diffX/2.5;
    		diffY = _root.targetY-_root.main.mc_bigImageBg._y;
    		_root.main.mc_bigImageBg._y += diffY/2.5;
    		diffX2 = _root.targetX-txtImageTitle._x;
    		txtImageTitle._x += diffX2/2.5;
    		diffY2 = _root.targetY2-txtImageTitle._y;
    		txtImageTitle._y += diffY2/2.5;
    		diffWidth = _root.targetWidth-_root.main.mc_bigImageBg._width;
    		diffHeight = _root.targetHeight-_root.main.mc_bigImageBg._height;
    		_root.main.mc_bigImageBg._width += diffWidth/2.5;
    		_root.main.mc_bigImageBg._height += diffHeight/2.5;
    		if (Math.abs(diffX)<1 && Math.abs(diffY)<1) {
    			delete _parent.onEnterFrame;
    			//load image
    			_root.main.big_mc.big_mc_image.my_mc.loadClip(thePicPath, "_root.main.big_mc.big_mc_image.container");
    		}
    	};
    	
    	//_root.main.big_mc.onRelease = function() {
    //		getURL(theLinkURL, "_blank");
    //	};
    	
    	var alfa:Number = 0;
    	var percentage:Number = 0;
    	var amountLoaded:Number = 0;
    	if (theImageName != undefined) {
    		_root.main.txtImageTitle.text = theImageName;
    	} else {
    		_root.main.txtImageTitle.text = "";
    	}
    }
    function changeColor():Void {
    	var colorComponent:Number = 500;
    	onEnterFrame = function () {
    		if (_root.largeImageEffect.toUpperCase() == "ON") {
    			myColor = new Color(_root.main.big_mc.big_mc_image.container);
    			myColTr = new Object();
    			colorComponent += (100-colorComponent)/10;
    			myColTr = {ra:colorComponent, ga:colorComponent, ba:colorComponent};
    			myColor.setTransform(myColTr);
    			if (Math.round(colorComponent) == 100) {
    				delete this.onEnterFrame;
    				colorComponent = 500;
    			}
    		} else {
    			_root.main.big_mc.big_mc_image.container._alpha += 7;
    			if (_root.main.big_mc.big_mc_image.container._alpha>=100) {
    				delete this.onEnterFrame;
    				_root.main.big_mc.big_mc_image.container._alpha = 100;
    			}
    		}
    	};
    }
    Last edited by oracleguy; 02-16-2009 at 07:27 AM. Reason: Be kind: use code tags

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Holy cow, thats a lot of code.

    Can you please give me some direction as to where you found this, and please put it inside of code tags so I can read it better. It will help me to have a starting point, as well as could you provide an example link?

    Also a challenge for you: Can you point out the points which the script controls the currently viewed image, and the points at which those images are changed? Bonus points will be awarded!
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •