Jump to content


Photo

Actionscript scroll speed?


  • Please log in to reply
2 replies to this topic

#1 Hooch

Hooch

    Young Padawan

  • Members
  • Pip
  • 158 posts
  • Location:Brockville, Ontario

Posted 01 August 2009 - 08:17 PM

Hello all
I was hoping someone might be able to find the speed of the
thumbnail scroll in the actionscript.
I tried editing what I thought might be...but it never worked.
Here is the code
// Advanced XML Image Gallery v1.2
//
// INITIAL SETTINGS
//
import mx.transitions.Tween;
import mx.transitions.easing.*;
// Set first gallery displayed by default
galleryID = 0;
// Set first image displayed by default
ID = 0;
// Set your document stage width and height here
stageW = 800;
stageH = 600;
// Set spacing amount between thumbnail images
thumbSpace = 1;
// Set the maximum amount of thumbs to be displayed here. Scrolling will be enabled if total of thumbs is greater than default_maxThumbs
default_maxThumbs = 8;
// Set border amount here
border = 15;
menu_mc.bgX = menu_mc.bg._x;
// Set initial size of white bg here
destWidth = bg_mc.bg._width=100;
destHeight = bg_mc.bg._height=100;
//
// CLIP DEFAULTS
//
// Original positions
fullscreen_mcY = fullscreen_mc._y;
bgX = bg._x;
bgY = bg._y;
menu_mcX = menu_mc._x;
menu_mcY = menu_mc._y;
select_mcY = select_mc._y;
autoPlay_mcY = autoPlay_mc._y;
// Initial visibility
hover_mc._visible = false;
info_mc._alpha = 0;
info_mc.destAlpha = 0;
bttnNext._visible = false;
bttnPrev._visible = false;
menu_all._visible = false;
holder._alpha = 0;
//
// VARIABLE DEFAULTS
//
destWidth = holder._width+border;
destHeight = holder._height+border;
//
// CSS STYLESHEET
//
var styles = new TextField.StyleSheet();
// Set hyperlink colour and decoration here
styles.setStyle("a:link", {color:'#E3E3E3', textDecoration:'none'});
styles.setStyle("a:hover", {color:'#fb0f0f', textDecoration:'underline'});
info_mc.txt.html = true;
info_mc.txt.styleSheet = styles;
//
// ON STAGE RESIZE 
//
stageListener = new Object();
Stage.addListener(stageListener);
alignObjects = function () {
	// Align BG
	bg._x = bgX-(Stage.width-stageW)/2;
	bg._y = bgY-(Stage.height-stageH)/2;
	bg._width = Stage.width;
	bg._height = Stage.height;
	// Align Menu
	menu_mc._x = menu_mcX-(Stage.width-stageW)/2+(Stage.width-stageW)/2;
	menu_mc._y = menu_mcY+(Stage.height-stageH)/2;
	menu_mc.bg._x = menu_mc.bgX-(Stage.width-stageW)/2;
	menu_mc.bg._width = Stage.width;
	// Align Autoplay
	autoPlay_mc._x = -(Stage.width-stageW)/2+Stage.width-autoPlay_mc._width-40;
	autoPlay_mc._y = autoPlay_mcY+(Stage.height-stageH)/2;
	// Align Select Menu
	select_mc._x = -(Stage.width-stageW)/2+10;
	select_mc._y = select_mcY+(Stage.height-stageH)/2;
	// Align Fullscreen
	fullscreen_mc._x = -(Stage.width-stageW)/2+Stage.width-fullscreen_mc._width-10;
	fullscreen_mc._y = fullscreen_mcY+(Stage.height-stageH)/2;
};
stageListener.onResize = function() {
	alignObjects();
};
alignObjects();
//
// AUTOPLAY FUNCTION
//
slideTimer = function () {
	if (!bg_mc.hitTest(_root._xmouse, _root._ymouse, true)) {
		clearInterval(_global.timeInterval);
		if (slideShow == "true") {
			ID += 1;
			if (ID == total) {
				ID = 0;
				galleryID += 1;
				if (galleryID == galleryTotal) {
					galleryID = 0;
				}
				buildGallery();
			}
			select_mc.selectShow.txt_mc.txt.text = xmlNode.childNodes[galleryID].attributes.Name;
			menu_mc.scroll_mc.thumb_mc["thumb"+ID].selectThumb();
			loadID();
		}
	}
};
//
// AUTOPLAY BUTTON
//
autoPlay_mc.bttn.onPress = function() {
	if (this._parent._currentframe == 1) {
		slideShow = "true";
		this._parent.gotoAndStop(2);
		slideTimer();
	} else {
		slideShow = "false";
		this._parent.gotoAndStop(1);
		clearInterval(_global.timeInterval);
	}
};
//
// BUTTON FUNCTIONS 
//
bg_mc.bg.bttnNext.onRelease = function() {
	nextID();
	menu_mc.scroll_mc.thumb_mc["thumb"+ID].selectThumb();
};
bg_mc.bg.bttnNext.onRollOver = function() {
	bttnNext._visible = true;
};
bg_mc.bg.bttnNext.onRollOut = bg_mc.bg.bttnNext.onDragOut=function () {
	bttnNext._visible = false;
};
bg_mc.bg.bttnPrev.onRelease = function() {
	prevID();
	menu_mc.scroll_mc.thumb_mc["thumb"+ID].selectThumb();
};
bg_mc.bg.bttnPrev.onRollOver = function() {
	bttnPrev._visible = true;
};
bg_mc.bg.bttnPrev.onRollOut = bg_mc.bg.bttnPrev.onDragOut=function () {
	bttnPrev._visible = false;
};
info_bttn.bttn.onRelease = function() {
	getURL(url[ID], "_blank");
};
info_bttn.bttn.onRollOver = function() {
	info_mc.destAlpha = 100;
};
info_bttn.bttn.onRollOut = info_bttn.bttn.onDragOut=function () {
	info_mc.destAlpha = 0;
};
//
// LOAD ID FUNCTIONS
//
nextID = function () {
	// Switch off slideshow mode if next pressed
	slideShow = "false";
	// Get next ID
	if (ID<(total-1)) {
		ID++;
		loadID();
	}
};
prevID = function () {
	// Switch off slideshow mode if previous pressed
	slideShow = "false";
	// Get previous ID
	if (ID>0) {
		ID--;
		loadID();
	}
};
loadID = function () {
	tweenAlphaPreloader.stop();
	tweenAlphaPreloader.rewind();
	preloader._alpha = 100;
	tweenAlpha.rewind();
	tweenAlpha.stop();
	destAlpha = 0;
	holder._alpha = 0;
	info_mc._alpha = 0;
	info_mc.destAlpha = 0;
	bg.newHEX = Colour[ID];
	menu_mc.hover.txt.text = Caption[ID];
	loadMovie(Large[ID], holder);
	if (slideShow == "true") {
		autoPlay_mc.gotoAndStop(2);
	} else {
		autoPlay_mc.gotoAndStop(1);
	}
};
thumbPress = function () {
	// Switch off slideshow mode if thumb pressed
	slideShow = "false";
	loadID();
};
//
// DISPLAY INFO TEXT
//
setText = function () {
	info_mc.bg._width = holder._width;
	info_mc.txt.htmlText = Copy[ID];
	info_mc.txt._width = info_mc.bg._width-20;
	info_mc.txt._x = info_mc.bg._x+10;
	info_mc.txt._height = info_mc.txt.textHeight+15;
	info_mc.bg._height = info_mc.txt._height+10;
	info_mc._x = holder._x;
	info_mc._y = holder._y+holder._height-info_mc._height;
};
//
// ON IMAGE LOAD
//
alignPic = function () {
	holder._x = (stageW-holder._width)/2;
	holder._y = (stageH-holder._height-menu_mc._height)/2;
	bg_mc.bg._x = holder._x;
	bg_mc.bg._y = holder._y;
	bg_mc._x = holder._width/2;
	bg_mc._y = holder._height/2;
	bttnNext._y = holder._y+(holder._height-bttnNext._height)/2;
	bttnNext._x = bg_mc._width+(stageW-bg_mc._width)/2-bttnNext._width-border/2;
	bttnPrev._y = holder._y+(holder._height-bttnPrev._height)/2;
	bttnPrev._x = (stageW-bg_mc._width)/2+bttnPrev._width+border/2;
	preloader._x = holder._x+holder._width/2;
	preloader._y = holder._y+holder._height/2;
};
alignPic();
//
// LARGE IMAGE TRANSITION
//
// You can use custom easing types such as: Back, Bounce, Elastic, Regular, Strong, None
var tweenAlpha:Tween = new Tween(holder, "_alpha", Strong.easeOut, 0, 100, 25, false);
tweenAlpha.stop();
var tweenAlphaPreloader:Tween = new Tween(preloader, "_alpha", Strong.easeOut, 100, 0, 25, false);
tweenAlphaPreloader.stop();
imageLoaded = function () {
	holder._alpha = 0;
	tweenAlpha.rewind();
	tweenAlpha.stop();
	currWidth = bg_mc.bg._width;
	currHeight = bg_mc.bg._height;
	destWidth = holder._width+border;
	destHeight = holder._height+border;
	// You can use custom easing types such as: Back, Bounce, Elastic, Regular, Strong, None
	var tweenWidth:Tween = new Tween(bg_mc.bg, "_width", Strong.easeOut, currWidth, destWidth, 25, false);
	var tweenHeight:Tween = new Tween(bg_mc.bg, "_height", Strong.easeOut, currHeight, destHeight, 25, false);
	tweenAlphaPreloader.start();
	tweenWidth["onMotionFinished"] = function () {
		if (tweenWidth.position == destWidth && tweenAlpha.position == 0) {
			tweenAlpha.start();
		}
	};
	// Check if autoplay is enabled
	if (slideShow == "true") {
		clearInterval(_global.timeInterval);
		_global.timeInterval = setInterval(slideTimer, Delay);
	} else {
		clearInterval(_global.timeInterval);
	}
};
//
// BUILD GALLERY FUNCTION
//
buildGallery = function () {
	menu_all.destX = menu_all.header_mc._width+1+(menu_all.menu_mc._width+1)*galleryID;
	menu_all.doTween();
	ID = 0;
	destWidth = 0;
	destHeight = 0;
	//Remove previously created photos and thumbs
	for (j=0; j<currentTotal; j++) {
		menu_mc.scroll_mc.thumb_mc["thumb"+j].removeMovieClip();
	}
	total = xmlNode.childNodes[galleryID].childNodes.length;
	maxThumbs = default_maxThumbs;
	//Disable scrolling if too few thumbs
	if (maxThumbs>total) {
		maxThumbs = total;
	}
	// Sets destination width and height for each image																				 
	for (i=0; i<total; i++) {
		Thumb[i] = xmlNode.childNodes[galleryID].childNodes[i].attributes.Thumb;
		Large[i] = xmlNode.childNodes[galleryID].childNodes[i].attributes.Large;
		Caption[i] = xmlNode.childNodes[galleryID].childNodes[i].attributes.Caption;
		Colour[i] = xmlNode.childNodes[galleryID].childNodes[i].attributes.Colour;
		Copy[i] = xmlNode.childNodes[galleryID].childNodes[i].childNodes[0].firstChild.nodeValue;
		//Build thumb menu
		menu_mc.scroll_mc.thumb_mc.thumb.duplicateMovieClip("thumb"+i, i);
		menu_mc.scroll_mc.thumb_mc["thumb"+i]._x = (menu_mc.scroll_mc.thumb_mc["thumb"+i]._width+thumbSpace)*i;
		loadMovie(Thumb[i], menu_mc.scroll_mc.thumb_mc["thumb"+i].holder);
		menu_mc.scroll_mc.thumb_mc["thumb"+i].ID = i;
		menu_mc.scroll_mc.mask_mc._width = ((menu_mc.scroll_mc.thumb_mc.thumb._width+thumbSpace)*maxThumbs)-thumbSpace;
		menu_mc.scroll_mc._x = Math.round(-(Stage.width-stageW)/2+Stage.width/2-menu_mc.scroll_mc.mask_mc._width/2);
		//Reset scroll menu to first image on gallery load
		menu_mc.scroll_mc.thumb_mc._x = 0;
		menu_mc.scroll_mc.destX = 0;
	}
	loadID();
	currentTotal = total;
};
//
// THUMBNAIL MENU AND PRELOADER SCRIPT
//
this.menu_mc.thumb_menu.destX = this.menu_mc.thumb_menu._x;
onEnterFrame = function () {
	// Align large image
	alignPic();
	this.menu_mc.thumb_menu._x += (this.menu_mc.thumb_menu.destX-this.menu_mc.thumb_menu._x)/3;
	//Info show and hide
	info_mc._alpha += (info_mc.destAlpha-info_mc._alpha)/3;
	header_mc._alpha = info_mc._alpha;
	loaded = holder.getBytesLoaded();
	filesize = holder.getBytesTotal();
	percentage = Math.round((loaded/filesize)*100);
	// Preloader script
	if (filesize == loaded && filesize>100) {
		preloader.left.half._rotation = 180;
		preloader.right.half._rotation = 180;
		if (bg_mc.hitTest(_root._xmouse, _root._ymouse, true) && holder._alpha>=100) {
			if (!bttnNext.hitTest(_root._xmouse, _root._ymouse, true) && !bttnPrev.hitTest(_root._xmouse, _root._ymouse, true)) {
				setText();
				info_mc.destAlpha = 100;
			} else {
				info_mc.destAlpha = 0;
			}
		} else {
			info_mc.destAlpha = 0;
		}
	} else {
		info_mc._alpha = 0;
		info_mc.destAlpha = 0;
		if (isNaN(percentage) or percentage == 0) {
			percentage = 0;
			preloader.left.half._rotation = 0;
			preloader.right.half._rotation = 0;
		} else if (percentage<=50 && percentage>0) {
			preloader.left.half._rotation = 0;
			preloader.right.half._rotation = (360/100)*percentage;
		} else if (percentage>50 && percentage<100) {
			preloader.left.half._rotation = (360/100)*(percentage-50);
			preloader.right.half._rotation = 180;
		}
	}
	preloader.percentageTxt = percentage;
};
//
// LOAD XML DATA
//
loadXML = function (loaded) {
	if (loaded) {
		xmlNode = this.firstChild;
		Name = [];
		Thumb = [];
		Large = [];
		Caption = [];
		Colour = [];
		Copy = [];
		galleryTotal = xmlNode.childNodes.length;
		select_mc.selectShow.txt_mc.txt.text = xmlNode.childNodes[galleryID].attributes.Name;
		// Get slideshow value from XML
		slideShow = xmlNode.attributes.AutoPlay;
		// Get slideshow delay value from XML
		Delay = xmlNode.attributes.Delay;
		// Build gallery select menu	  
		for (n=0; n<galleryTotal; n++) {
			Name[n] = xmlNode.childNodes[n].attributes.Name;
			select_mc.selectBttn_mc.selectBttn.duplicateMovieClip("selectBttn"+n, n);
			select_mc.selectBttn_mc["selectBttn"+n]._y = -select_mc.selectBttn_mc.selectBttn._height-(select_mc.selectBttn_mc.selectBttn._height)*n;
			select_mc.selectBttn_mc["selectBttn"+n].txt_mc.txt.text = Name[n];
			select_mc.selectBttn_mc["selectBttn"+n].ID = n;
		}
		buildGallery();
	} else {
		trace("Error loading XML");
	}
};
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("content.php");
stop();
(that's if it is in this code???)
Thank you for any help.

#2 Hooch

Hooch

    Young Padawan

  • Members
  • Pip
  • 158 posts
  • Location:Brockville, Ontario

Posted 01 August 2009 - 08:22 PM

oh...here is the scroll_mc
//Set boundry mask
thumb_mc.setMask(mask_mc);
//Buffer size left and right of menu
buffer = (thumb_mc.thumb._width)*2;
//Detect mouse position
this.onMouseMove = function() {
	if (this._xmouse>0 && this._xmouse<(boundryWidth)) {
		if (this._ymouse>0 && this._ymouse<(boundryHeight)) {
			ratio = this._xmouse/boundryWidth;
			diff = thumb_mc._width-boundryWidth+buffer;
			destX = Math.floor(-ratio*diff)+buffer/2;
		}
	}
};
//Scroll easing
this.onEnterFrame = function() {
	boundryWidth = mask_mc._width;
	boundryHeight = mask_mc._height;
	thumb_mc._x += (destX-thumb_mc._x)/1;
	thumb_mc._x = Math.round(thumb_mc._x);
	if (thumb_mc._x>0) {
		thumb_mc._x = 0;
	} else if (thumb_mc._x<(boundryWidth-thumb_mc._width)) {
		thumb_mc._x = boundryWidth-thumb_mc._width;
	}
};
stop();

How the scroll works is the left side of the thumbs you see is thumb 1.
Then as your mouse moves to the right the thumbs scroll up in numbers.
As you hit the left side of visible thumbs, it's the last thumb in the series.
The current series has over 50 thumbs. So the scroll just flies along.

I'm not sure if this is possible, but thanks for looking

Edited by Hooch, 01 August 2009 - 08:33 PM.


#3 GRIMESD

GRIMESD

    Young Padawan

  • Members
  • Pip
  • 10 posts
  • Gender:Male
  • Location:Upstate New York
  • Interests:I have been working with web design for a few years now and recently gained much interest in flash. I am self-teaching myself AS3 while also giving tutorials to help others out with what I have learned.

Posted 19 August 2009 - 08:29 AM

oh...here is the scroll_mc

//Set boundry mask
 thumb_mc.setMask(mask_mc);
 //Buffer size left and right of menu
 buffer = (thumb_mc.thumb._width)*2;
 //Detect mouse position
 this.onMouseMove = function() {
	 if (this._xmouse>0 && this._xmouse<(boundryWidth)) {
		 if (this._ymouse>0 && this._ymouse<(boundryHeight)) {
			 ratio = this._xmouse/boundryWidth;
			 diff = thumb_mc._width-boundryWidth+buffer;
			 destX = Math.floor(-ratio*diff)+buffer/2;
		 }
	 }
 };
 //Scroll easing
 this.onEnterFrame = function() {
	 boundryWidth = mask_mc._width;
	 boundryHeight = mask_mc._height;
	 thumb_mc._x += (destX-thumb_mc._x)/1;
	 thumb_mc._x = Math.round(thumb_mc._x);
	 if (thumb_mc._x>0) {
		 thumb_mc._x = 0;
	 } else if (thumb_mc._x<(boundryWidth-thumb_mc._width)) {
		 thumb_mc._x = boundryWidth-thumb_mc._width;
	 }
 };
 stop();

How the scroll works is the left side of the thumbs you see is thumb 1.
Then as your mouse moves to the right the thumbs scroll up in numbers.
As you hit the left side of visible thumbs, it's the last thumb in the series.
The current series has over 50 thumbs. So the scroll just flies along.

I'm not sure if this is possible, but thanks for looking


//Scroll easing
this.onEnterFrame = function() {
	boundryWidth = mask_mc._width;
	boundryHeight = mask_mc._height;
	thumb_mc._x += (destX-thumb_mc._x)/1;
	thumb_mc._x = Math.round(thumb_mc._x);
	if (thumb_mc._x>0) {
		thumb_mc._x = 0;
	} else if (thumb_mc._x<(boundryWidth-thumb_mc._width)) {
		thumb_mc._x = boundryWidth-thumb_mc._width;
	}
};
stop();

I am not proficient in math functions yet, but I believe your answer lies in this section of the code. "Easing" is the act of moving a object at a certain speed which is controlled by actionscript. So, with that said, the answer is probably in here somehow, good luck!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users