home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Canadian Forces: Prepare for Takeoff as a Pilot
/
CF_FS_Air.iso.iso
/
pc
/
data
/
swf
/
flashpaper
/
103.swf
/
scripts
/
FSliderSymbol.as
next >
Wrap
Text File
|
2004-06-30
|
11KB
|
399 lines
FSliderClass = function()
{
this.width = !this.horizontal ? this._height : this._width;
super();
this._xscale = this._yscale = 100;
this._rotation = 0;
this.attachMovie("fsl_scrollTrack","scrollTrack_mc",this.depth++,{_y:1});
this.setThumbSymbol(this.thumbSymbol);
this.setEnabled(this.enabled);
if(this.minValue >= this.maxValue)
{
this.minValue = 0;
this.maxValue = 100;
}
this.setSliderProperties(this.minValue,this.maxValue);
this.setTickFrequency(this.tickFrequency);
this.setStyleProperty("fillFace",this.fillColor,true);
delete this.fillColor;
this.setSize(this.width);
this.setHorizontal(this.horizontal);
this.setChangeHandler(this.changeHandler);
};
FSliderClass.prototype = new FUIComponentClass();
Object.registerClass("FSliderSymbol",FSliderClass);
FSliderClass.prototype.depth = 0;
FSliderClass.prototype.minValue = 0;
FSliderClass.prototype.maxValue = 100;
FSliderClass.prototype.range = 100;
FSliderClass.prototype.value = 0;
FSliderClass.prototype.tickFrequency = 2;
FSliderClass.prototype.tickJumpSize = 10;
FSliderClass.prototype.tickHeight = 2;
FSliderClass.prototype.tickSpacing = 3;
FSliderClass.prototype.tickStyle = "none";
FSliderClass.prototype.tickSnapping = false;
FSliderClass.prototype.sm_stepAmount = 1;
FSliderClass.prototype.lg_stepAmount = 5;
FSliderClass.prototype.horizontal = true;
FSliderClass.prototype.thumbSymbol = "fsl_squareThumb";
FSliderClass.prototype.fillColor = 13421772;
FSliderClass.prototype.getMinValue = function()
{
return this.minValue;
};
FSliderClass.prototype.getSnapToTicks = function()
{
return this.tickSnapping;
};
FSliderClass.prototype.getIntValue = function()
{
return Math.round(this.value);
};
FSliderClass.prototype.getTickStyle = function()
{
return this.tickStyle;
};
FSliderClass.prototype.getThumbSymbol = function()
{
return this.thumbSymbol;
};
FSliderClass.prototype.getHorizontal = function()
{
return this.horizontal;
};
FSliderClass.prototype.getTickFrequency = function()
{
return this.tickFrequency;
};
FSliderClass.prototype.getSmallStepAmount = function()
{
return this.sm_stepAmount;
};
FSliderClass.prototype.getLargeStepAmount = function()
{
return this.lg_stepAmount;
};
FSliderClass.prototype.getMaxValue = function()
{
return this.maxValue;
};
FSliderClass.prototype.getValue = function()
{
return this.value;
};
FSliderClass.prototype.setSize = function(width)
{
if(width < 4)
{
return false;
}
this.width = width;
this.scrollableArea = !this.thumb_mc ? this.width - 5 : this.width - 2 - this.thumb_mc._width;
this.scrollTrack_mc._x = this.width / 2;
this._drawTicks();
this.setValue(this.value);
};
FSliderClass.prototype.setSnapToTicks = function(snap)
{
this.tickSnapping = snap;
this.setValue(this.value);
};
FSliderClass.prototype.setSliderProperties = function(min, max)
{
if(max <= min)
{
return false;
}
this.maxValue = Number(max);
this.minValue = Number(min);
if(isNaN(this.maxValue) || isNaN(this.minValue))
{
return false;
}
this.range = this.maxValue - this.minValue;
this.setTickFrequency(this.tickFrequency);
this.setValue(this.value);
};
FSliderClass.prototype.setEnabled = function(enable)
{
super.setEnabled(enable);
this.enabled = enable;
if(!enable)
{
this.scrollTrack_mc.gotoAndStop("disabled");
this.thumb_mc.gotoAndStop("disabled");
delete this.onPress;
delete this.onRelease;
delete this.onReleaseOutside;
delete this.onMouseMove;
}
else
{
this.scrollTrack_mc.gotoAndStop(1);
this.thumb_mc.gotoAndStop(1);
this.onPress = this._onPress;
this.onRollOver = this._onRollOver;
this.onRollOut = this._onRollOut;
this.onRelease = this.onReleaseOutside = this._onRelease;
}
this.setSize(this.width);
};
FSliderClass.prototype.setTickStyle = function(style)
{
this.tickStyle = style;
this._drawTicks();
};
FSliderClass.prototype.setThumbSymbol = function(symbol)
{
var depth;
this.thumbSymbol = symbol;
if(this.thumb_mc)
{
depth = this.thumb_mc.getDepth();
this.thumb_mc.removeMovieClip();
}
else
{
depth = this.depth++;
}
this.attachMovie(symbol,"thumb_mc",depth);
this.setSize(this.width);
};
FSliderClass.prototype.setHorizontal = function(horizontal)
{
if(horizontal)
{
this._rotation = 0;
this._xscale = 100;
this.scrollTrack_mc._rotation = 0;
this.scrollTrack_mc._yscale = 100;
}
else if(!horizontal)
{
this._rotation = 90;
this.scrollTrack_mc._rotation = 180;
this.scrollTrack_mc._yscale = -100;
}
this.horizontal = horizontal;
this.setValue(this.getValue());
};
FSliderClass.prototype.setSmallStepAmount = function(step)
{
if(step < 1)
{
return false;
}
this.sm_stepAmount = Number(step);
};
FSliderClass.prototype.setLargeStepAmount = function(step)
{
if(step < 1)
{
return false;
}
this.lg_stepAmount = Number(step);
};
FSliderClass.prototype.setValue = function(value)
{
var callHandler = false;
value = Math.min(Math.max(value,this.minValue),this.maxValue);
if(this.tickSnapping)
{
value = this._snapValue(value);
}
if(this.snapValues != undefined && this.snapValues.length > 0)
{
var i = 0;
while(i < this.snapValues.length)
{
if(value >= this.snapValues[i] - this.snapThreshold && value <= this.snapValues[i] + this.snapThreshold)
{
value = this.snapValues[i];
break;
}
i++;
}
}
if(this.value != value)
{
callHandler = true;
}
this.value = value;
var xPos = this.valueToCoord(value);
this.thumb_mc._x = xPos;
this.scrollTrack_mc.left_mc._x = (- this.width) / 2;
var rightElement = this.scrollTrack_mc.middleRight_mc;
var leftElement = this.scrollTrack_mc.middleLeft_mc;
if(!this.horizontal)
{
xPos = this.valueToCoord(this.range - value + this.minValue * 2);
}
leftElement._width = xPos + this.thumb_mc._width / 2;
leftElement._x = this.scrollTrack_mc.left_mc._x + this.scrollTrack_mc.left_mc._width;
rightElement._width = this.width - xPos - this.scrollTrack_mc.left_mc._width - this.scrollTrack_mc.right_mc._width - (this.thumb_mc._width - 2) / 2;
rightElement._x = leftElement._x + leftElement._width;
this.scrollTrack_mc.right_mc._x = rightElement._x + rightElement._width;
this.executeCallBack();
};
FSliderClass.prototype.setTickFrequency = function(frequency)
{
frequency = Number(frequency);
if(isNaN(frequency))
{
return false;
}
frequency = Math.max(frequency,2);
this.tickFrequency = frequency;
this.tickJumpSize = this.range / (this.tickFrequency - 1);
this._drawTicks();
this.setValue(this.value);
};
FSliderClass.prototype._onMouseMove = function()
{
this.setValueFromThumb();
};
FSliderClass.prototype._onRelease = function()
{
this.focused = false;
this.setValueFromThumb();
delete this.onMouseMove;
delete this.thumbPressed;
delete this.distanceFromCenter;
this.thumb_mc.gotoAndStop(1);
this.myOnKillFocus();
Selection.setFocus(null);
};
FSliderClass.prototype._snapValue = function(value)
{
return Math.round((value - this.minValue) / this.tickJumpSize) * this.tickJumpSize + this.minValue;
};
FSliderClass.prototype.getValueFromThumb = function()
{
var xMouse;
if(!this.thumbPressed)
{
xMouse = this._xmouse - this.thumb_mc._width / 2;
}
else
{
xMouse = this._xmouse - this.distanceFromCenter;
}
xMouse = Math.max(1,Math.min(xMouse,this.scrollableArea + 1));
return this.coordToValue(xMouse);
};
FSliderClass.prototype._onPress = function()
{
this.pressFocus();
this.thumbPressed = this.thumb_mc.hitTest(_root._xmouse,_root._ymouse);
if(this.thumbPressed)
{
this.distanceFromCenter = this._xmouse - this.thumb_mc._x;
}
this.setValueFromThumb();
this.onMouseMove = this._onMouseMove;
this.thumb_mc.gotoAndStop("pressed");
this.myOnSetFocus();
};
FSliderClass.prototype._onRollOver = function()
{
this.thumb_mc.gotoAndStop("over");
};
FSliderClass.prototype._onRollOut = function()
{
this.thumb_mc.gotoAndStop(1);
};
FSliderClass.prototype.setValueFromThumb = function()
{
this.setValue(this.getValueFromThumb());
};
FSliderClass.prototype.coordToValue = function(coord)
{
if(this.horizontal)
{
var value = (coord - 1) / this.scrollableArea * this.range + this.minValue;
}
else
{
var value = Math.abs(coord - 1 - this.scrollableArea) / this.scrollableArea * this.range + this.minValue;
}
return value;
};
FSliderClass.prototype.valueToCoord = function(value)
{
if(this.horizontal)
{
return (value - this.minValue) / this.range * this.scrollableArea + 1;
}
return Math.abs(value - (this.range + this.minValue)) / this.range * this.scrollableArea + 1;
};
FSliderClass.prototype._drawTicks = function()
{
var depth;
if(!this.tick_mc)
{
this.createEmptyMovieClip("tick_mc",this.depth++);
this.registerSkinElement(this.tick_mc,"tickColor");
}
this.tick_mc.clear();
var curValue = this.minValue;
var y = this.scrollTrack_mc._height + this.scrollTrack_mc._y + this.tickSpacing;
var i = 0;
while(i < this.tickFrequency)
{
var x = this.valueToCoord(curValue);
x += this.thumb_mc._width / 2;
curValue += this.tickJumpSize;
if(this.tickStyle == "bottom" || this.tickStyle == "both")
{
with(this.tick_mc)
{
lineStyle(0,0);
moveTo(x,y);
lineTo(x,y + this.tickHeight);
}
}
if(this.tickStyle == "top" || this.tickStyle == "both")
{
with(this.tick_mc)
{
lineStyle(0,0);
moveTo(x,- this.tickSpacing + 1);
lineTo(x,- this.tickSpacing - this.tickHeight + 1);
}
}
i++;
}
};
FSliderClass.prototype.myOnKeyDown = function()
{
if(!this.enable)
{
return undefined;
}
var increase = !!this.horizontal ? 39 : 38;
var decrease = !!this.horizontal ? 37 : 40;
var code = Key.getCode();
var step = !Key.isDown(17) ? this.sm_stepAmount : this.lg_stepAmount;
if(this.tickSnapping && step < this.tickJumpSize)
{
step = this.tickJumpSize;
}
if(code == increase)
{
this.setValue(this.value + step);
}
else if(code == decrease)
{
this.setValue(this.value - step);
}
};
FSliderClass.prototype.setSnapValues = function(_array)
{
this.snapValues = _array;
};
FSliderClass.prototype.setSnapThreshold = function(_i)
{
this.snapThreshold = _i;
};