📄 preloadprogressbar.as
字号:
// borderRect
//----------------------------------
/**
* The dimensions of the border of the display.
* This is a read-only property which you must override
* if you need to change it.
*/
protected function get borderRect():RoundedRectangle
{
return new RoundedRectangle(0, 0, 310, 90, 4);
}
//----------------------------------
// downloadingLabel
//----------------------------------
/**
* @private
* Storage for the downloadingLabel property.
*/
private var _downloadingLabel:String = "Loading";
/**
* The string to display as the label while in the downloading phase.
*
* @default "Loading"
*/
protected function get downloadingLabel():String
{
return _downloadingLabel;
}
/**
* @private
*/
protected function set downloadingLabel(value:String):void
{
_downloadingLabel = value;
}
//----------------------------------
// initializingLabel
//----------------------------------
/**
* @private
* Storage for the initializingLabel property.
*/
private static var _initializingLabel:String = "Initializing";
/**
* The string to display as the label while in the initializing phase.
*
* @default "Initializing"
*/
public static function get initializingLabel():String
{
return _initializingLabel;
}
/**
* @private
*/
public static function set initializingLabel(value:String):void
{
_initializingLabel = value;
}
//----------------------------------
// label
//----------------------------------
/**
* @private
* Storage for the label property.
*/
private var _label:String = "";
/**
* Text to display when the progress bar is active.
* The Preloader class sets this value
* before displaying the progress bar.
* Implementing this property in a subclass is optional.
*
* @default ""
*/
protected function get label():String
{
return _label;
}
/**
* @private
*/
protected function set label(value:String):void
{
if (!(value is Function))
_label = value;
draw();
}
//----------------------------------
// labelFormat
//----------------------------------
/**
* The TextFormat object of the TextField component of the label.
* This is a read-only property which you must override
* if you need to change it.
*/
protected function get labelFormat():TextFormat
{
var tf:TextFormat = new TextFormat();
tf.color = 0x333333;
tf.font = "Verdana";
tf.size = 10;
return tf;
}
//----------------------------------
// labelRect
//----------------------------------
/**
* The dimensions of the TextField component for the label.
* This is a read-only property which you must override
* if you need to change it.
*/
protected function get labelRect():Rectangle
{
return new Rectangle(92, 30, 154, 16);
}
//----------------------------------
// linkButtonRect
//----------------------------------
/**
* The dimensions of the TextField component for the linkButton.
* This is a read-only property which you must override
* if you need to change it.
*/
protected function get linkButtonRect():Rectangle
{
return new Rectangle(92, 69, 204, 16);
}
protected function get linkButtonUrl():String
{
return "http://www.getoutsmart.com";
}
//----------------------------------
// linkButtonText
//----------------------------------
protected var linkButtonText:String = "developed by Outsmart";
protected var linkButtonOverColor:uint = 0xF0F0F0;
protected var linkButtonDownColor:uint = 0xF0F0F0;
//----------------------------------
// linkButtonFormat
//----------------------------------
/**
* The TextFormat object of the TextField component of the label.
* This is a read-only property which you must override
* if you need to change it.
*/
protected function get linkButtonFormat():TextFormat
{
var tf:TextFormat = new TextFormat();
tf.color = 0xAAAAAA;
tf.font = "Verdana";
tf.size = 10;
tf.align = "right";
return tf;
}
//----------------------------------
// percentFormat
//----------------------------------
/**
* The TextFormat of the TextField component for displaying the percent.
* This is a read-only property which you must override
* if you need to change it.
*/
protected function get percentFormat():TextFormat
{
var tf:TextFormat = new TextFormat();
tf.align = "right";
tf.color = 0x000000;
tf.font = "Verdana";
tf.size = 10;
return tf;
}
//----------------------------------
// percentRect
//----------------------------------
/**
* The dimensions of the TextField component for displaying the percent.
* This is a read-only property which you must override
* if you need to change it.
*/
protected function get percentRect():Rectangle
{
return new Rectangle(108, 4, 34, 16);
}
//----------------------------------
// showLabel
//----------------------------------
/**
* @private
* Storage for the showLabel property.
*/
private var _showLabel:Boolean = true;
/**
* Controls whether to display the label, <code>true</code>,
* or not, <code>false</code>.
*
* @default true
*/
protected function get showLabel():Boolean
{
return _showLabel;
}
/**
* @private
*/
protected function set showLabel(value:Boolean):void
{
_showLabel = value;
draw();
}
//----------------------------------
// showPercentage
//----------------------------------
/**
* @private
* Storage for the showPercentage property.
*/
private var _showPercentage:Boolean = false;
/**
* Controls whether to display the percentage, <code>true</code>,
* or not, <code>false</code>.
*
* @default true
*/
protected function get showPercentage():Boolean
{
return _showPercentage;
}
/**
* @private
*/
protected function set showPercentage(value:Boolean):void
{
_showPercentage = value;
draw();
}
//--------------------------------------------------------------------------
//
// Methods:IPreloaderDisplay
//
//--------------------------------------------------------------------------
/**
* Called by the Preloader after the download progress bar
* has been added as a child of the Preloader.
* This should be the starting point for configuring your download progress bar.
*/
public function initialize():void
{
_startTime = getTimer();
center(stageWidth, stageHeight);
// start loading logo
trace( logoUrl );
var urlReq:URLRequest = new URLRequest(logoUrl);
logoLoader.load(urlReq);
logoLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, logoLoadedHandler);
}
//----------------------------------
// logoLoadedHandler()
// set size and add child
//----------------------------------
private function logoLoadedHandler(event:Event):void
{
var rect:Shape = new Shape();
rect.graphics.beginFill(0xFFFFFF);
rect.graphics.drawRect( calcX(_borderRect.x), calcY(_borderRect.y),
_borderRect.width, _borderRect.height);
rect.graphics.endFill();
addChild(rect);
var ldr:Loader = new Loader();
logoLoader.mask = rect;
logoLoader.x = calcX(_borderRect.x);
logoLoader.y = calcY(_borderRect.y);
this.addChild(logoLoader);
}
//--------------------------------------------------------------------------
//
// Methods
//
//--------------------------------------------------------------------------
/**
* Centers the download progress bar based on the passed in dimensions.
*
* @param width The width of the area in which to center the download progress bar.
*
* @param height The height of the area in which to center the download progress bar.
*/
protected function center(width:Number, height:Number):void
{
_xOffset = Math.floor((width - _borderRect.width) / 2);
_yOffset = Math.floor((height - _borderRect.height) / 2);
}
/**
* @private
* Updates the display.
*/
private function draw():void
{
var percentage:Number;
if (_startedLoading)
{
if (!_startedInit)
{
// 0 to MaxDL Percentage
percentage = Math.round(getPercentLoaded(_value, _maximum) *
DOWNLOAD_PERCENTAGE / 100);
}
else
{
// MaxDL percentage to 100
percentage = Math.round((getPercentLoaded(_value, _maximum) *
(100 - DOWNLOAD_PERCENTAGE) / 100) +
DOWNLOAD_PERCENTAGE);
}
}
else
{
percentage = getPercentLoaded(_value, _maximum);
}
if (_labelObj)
_labelObj.text = _label;
if (_percentObj)
{
if (!_showPercentage)
{
_percentObj.visible = false;
_percentObj.text = "";
}
else
{
_percentObj.text = String(percentage) + "%";
}
}
if (_barSprite && _barFrameSprite)
{
if (!_showProgressBar)
{
_barSprite.visible = false;
_barFrameSprite.visible = false;
}
else
{
drawProgressBar(percentage);
}
}
}
/**
* Creates the subcomponents of the display.
*/
protected function createChildren():void
{
var g:Graphics = graphics;
var labelObj:TextField;
var percentObj:TextField;
// Draw the background first
// Same value as StyleManager.NOT_A_COLOR. However, we don't want to bring in StyleManager at this point.
/*if (backgroundColor != 0xFFFFFFFF)
{
g.beginFill(backgroundColor, backgroundAlpha);
g.drawRect(0, 0, stageWidth, stageHeight);
}*/
if (backgroundImage != null)
loadBackgroundImage(backgroundImage);
_barFrameSprite = new Sprite();
_barSprite = new Sprite();
addChild(_barFrameSprite);
addChild(_barSprite);
// Draw the outside border and fill.
g.beginFill(borderFillColor, borderFillAlpha);
g.drawRoundRect(calcX(_borderRect.x),
calcY(_borderRect.y),
_borderRect.width,
_borderRect.height,
_borderRect.cornerRadius * 2,
_borderRect.cornerRadius * 2);
g.drawRoundRect(calcX(_borderRect.x + 1),
calcY(_borderRect.y + 1),
_borderRect.width - 2,
_borderRect.height - 2,
_borderRect.cornerRadius - 1 * 2,
_borderRect.cornerRadius - 1 * 2);
g.endFill();
g.beginFill(borderFillColor, borderFillAlpha);
g.drawRoundRect(calcX(_borderRect.x + 1),
calcY(_borderRect.y + 1),
_borderRect.width - 2,
_borderRect.height - 2,
_borderRect.cornerRadius - 1 * 2,
_borderRect.cornerRadius - 1 * 2);
g.endFill();
var frame_g:Graphics = _barFrameSprite.graphics;
// Draw the bar frame border and fill
var matrix:Matrix = new Matrix();
matrix.createGradientBox(_barFrameRect.width, _barFrameRect.height,
Math.PI / 2, calcX(_barFrameRect.x), calcY(_barFrameRect.y));
frame_g.beginGradientFill(GradientType.LINEAR,
[ 0x5C6266, 0xB5B8BA ],
[ 1.0, 1.0 ],
[ 0, 0xFF ],
matrix);
frame_g.drawRoundRect(calcX(_barFrameRect.x),
calcY(_barFrameRect.y),
_barFrameRect.width,
_barFrameRect.height,
_barFrameRect.cornerRadius * 2,
_barFrameRect.cornerRadius * 2);
frame_g.drawRoundRect(calcX(_barFrameRect.x + 1),
calcY(_barFrameRect.y + 1),
_barFrameRect.width - 2,
_barFrameRect.height - 2,
_barFrameRect.cornerRadius * 2,
_barFrameRect.cornerRadius * 2);
frame_g.endFill();
// Attach the label TextField.
_labelObj = new TextField();
_labelObj.x = calcX(_labelRect.x);
_labelObj.y = calcY(_labelRect.y);
_labelObj.width = _labelRect.width;
_labelObj.height = _labelRect.height;
_labelObj.selectable = false;
_labelObj.defaultTextFormat = labelFormat;
addChild(_labelObj);
// Attach the percentage TextField.
_percentObj = new TextField();
_percentObj.x = calcX(_percentRect.x);
_percentObj.y = calcY(_percentRect.y);
_percentObj.width = _percentRect.width;
_percentObj.height = _percentRect.height;
_percentObj.selectable = false;
_percentObj.defaultTextFormat = percentFormat;
addChild(_percentObj);
// Create dropshadow
var ds:RectangularDropShadow = new RectangularDropShadow();
ds.color = 0x000000;
ds.angle = 90;
ds.alpha = .6;
ds.distance = 2;
ds.tlRadius = ds.trRadius = ds.blRadius = ds.brRadius = _borderRect.cornerRadius;
ds.drawShadow(g,
calcX(_borderRect.x),
calcY(_borderRect.y),
_borderRect.width,
_borderRect.height);
// Draw the top line
g.lineStyle(1,0xFFFFFF, .3);
g.moveTo(calcX(_borderRect.x) + _borderRect.cornerRadius, calcY(_borderRect.y));
g.lineTo(calcX(_borderRect.x) - _borderRect.cornerRadius + _borderRect.width, calcY(_borderRect.y));
// Create link button
createLinkButton();
}
private function createLinkButton():void
{
_linkButton = new PreloadLinkButton(linkButtonRect,linkButtonUrl,linkButtonText,linkButtonFormat,linkButtonOverColor,linkButtonDownColor);
_linkButton.x = calcX(_linkButtonRect.x);
_linkButton.y = calcY(_linkButtonRect.y);
this.addChild(_linkButton);
}
protected function onLinkButtonClick():void
{
navigateToURL(new URLRequest(linkButtonUrl));
}
/**
* @private
* Draws the progress bar.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -