Показать сообщение отдельно
Старый 12.11.2009, 14:11
warning1 вне форума Посмотреть профиль Отправить личное сообщение для warning1 Найти все сообщения от warning1
  № 2  
Ответить с цитированием
warning1

Регистрация: Aug 2008
Сообщений: 92
Код
Код AS1/AS2:
// ***************************************************************
// zMinimalTextSlider
// No-bull-shit text slider. Clean, simple, minimal.
// Intended to be used with the zMinimalTextButton component.
//
// Version 1.1.4
// Last update Jan 5th 2004
//
// By zeh - zeh@fatorcaos.com.br
// ***************************************************************
 
// Needed functions **********************************************
 
// Rule of three
rot = function (a, b, x) {
  return ((x * b) / a);
};
 
if (forceUpdate) {
	// This creates a function that checks the textfield value and updates accordingly.
	// This is needed because flash doesn't fire the onChanged() event when the textfield
	// is changed by a loadvariables command.
	// It's a bit ugly, but it's the only way
	var cc = this.createEmptyMovieClip("stupidController", 31337);
	cc.oldTx = tx.htmlText;
	cc.onEnterFrame = function() {
		if (this._parent.tx.htmlText != this.oldTx) {
			// new text loaded/modified
			this._parent.update();
		};
	};
}
 
// Resets the deal: reads the maximum number of visible lines
reset = function() {
	tx.scroll = 1;
}
 
// Update: called when the scroll has to be redraw
update = function() {
	if (!foreground.dragando) {
		if (tx.maxscroll > 1) {
			var totalLines = tx.bottomScroll - tx.scroll;
			// Enables
			_alpha = 100;
			if (tx.scroll > tx.maxscroll) tx.scroll = tx.maxscroll; // fixes a weird error of not updating .scroll when a part of the text is deleted from the end of the string
			foreground._height = rot(tx.maxscroll+totalLines,totalLines+1, background._height);
			if (useFgHeight) foreground._height = fgHeight;
			foreground._y = rot(tx.maxscroll-1,tx.scroll-1,background._height-foreground._height);
			foreground.onRollOver = background.onRollover = function() {
				// The foreground should do nothing on rollover. This block is used
				// to turn the movieclip into a "button", sort of.
			}
			foreground.useHandCursor = useHand;
			background.useHandCursor = useHand;
		} else {
			// Disables
			_alpha = disAlpha;
			foreground._y = 0;
			foreground._height = background._height;
			delete (foreground.onRollover);
			delete (background.onRollover);
			foreground.useHandCursor = false;
			background.useHandCursor = false;
		}
	}
}
 
 
// Scroller functions *********************************************
 
foreground.onLoad = function () {
	this.dragando = false;
	this.offset = 0;
};
 
foreground.onMouseDown = function () {
	// Checks if a drag should start
	if (this.hitTest (_root._xmouse, _root._ymouse, false)) {
		this.dragando = true;
		this.offset = this._y - _parent._ymouse;
	}
};
 
foreground.onMouseUp = function () {
	// Ends drag, if any
	this.dragando = false;
};
 
foreground.onMouseMove = function () {
	// Move and update, if being dragged
	if (this.dragando) {
		this._y = _parent._ymouse + this.offset;
		if (this._y < 0) this._y = 0;
		if ((this._y + this._height) > this._parent.background._height) this._y = this._parent.background._height - this._height;
		tx.scroll = Math.round(rot(this._parent.background._height-this._height, this._y, tx.maxscroll-1))+1;
	}
}
 
// Background functions *********************************************
background.onMouseDown = function () {
	// Verifies if the background has been clicked
	var totalLines = tx.bottomScroll - tx.scroll;
	if (this.hitTest (_root._xmouse, _root._ymouse, false) && !this._parent.foreground.hitTest (_root._xmouse, _root._ymouse, false)) {
		if (this._parent._ymouse < this._parent.foreground._y) {
			// Big scroll up
			this.contador = 0;
			this.onEnterFrame = function () {
				if (this.contador % 5 == 0)	tx.scroll -= totalLines;
				this.contador++;
				if (this._parent._ymouse >= this._parent.foreground._y) delete (this.onEnterFrame);
			}
		} else if (this._parent._ymouse > this._parent.foreground._y+this._parent.foreground._height) {
			// Big scroll down
			this.contador = 0;
			this.onEnterFrame = function () {
				if (this.contador % 5 == 0)	tx.scroll += totalLines;
				this.contador++;
				if (this._parent._ymouse <= this._parent.foreground._y+this._parent.foreground._height) delete (this.onEnterFrame);
			}
		}
	}
};
 
background.onMouseUp = function () {
	delete (this.onEnterFrame);
};
 
// Mousewheel functions *********************************************
 
this.onEnterFrame = function() {
	// Checks to see if it's inside this textfield's bounding box
 
	// I can't use a object watch event because there might be different
	// textfields on the same screen - an object property can't have
	// two different watchers.
	var mx = tx._parent._xmouse;
	var my = tx._parent._ymouse;
	if (mx >= tx._x && mx <= tx._x + tx._width && my >= tx._y && my <= tx._y + tx._height) {
		// It's IN
 
		// Mouse wheel movement is expressed in ticks, which are bigger
		// than simple line movements - they depend on the current mouse
		// wheel speed set on the user's system. This calculation is done
		// to reach a reasonable rate of line movement according to the
		// user's mouse wheel movement.
		ticksPerLine = 60;
		if ((_level0.__wheelDelta + 0) != 0) {
			tx.scroll -= (_level0.__wheelDelta/ticksPerLine);
			_level0.__wheelDelta = 0;
		}
	}
};
 
// Initializes ******************************************************
 
// Shortcuts
tx = _parent[textfield_name];
 
// Reset size to 1:1
background._height = this._height;
this._yscale = 100;
 
// Sets colors
clr = new Color(foreground);
clr.setRGB (fgColor);
foreground._alpha = fgAlpha;
 
clr = new Color(background);
clr.setRGB (bgColor);
background._alpha = bgAlpha;
 
delete (clr);
 
 
// Sets text update functions and initializes
tx.reset = reset;
tx.reset();
tx.onChanged = tx.onScroller = update;
tx.onChanged();
 
// End: sit down and wait ******************************************
 
stop();