📄 preloadprogressbar.as
字号:
package com.mh.preloader
{
import flash.display.DisplayObject;
import flash.display.GradientType;
import flash.display.Graphics;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.events.TimerEvent;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.utils.Timer;
import flash.utils.getDefinitionByName;
import flash.utils.getTimer;
import mx.events.FlexEvent;
import mx.events.RSLEvent;
import mx.graphics.RectangularDropShadow;
import mx.graphics.RoundedRectangle;
import mx.preloaders.IPreloaderDisplay;
import flash.display.Shape;
import flash.net.navigateToURL;
import flash.display.SimpleButton;
import flash.events.MouseEvent;
/**
* The DownloadProgressBar class displays download progress.
* It is used by the Preloader control to provide user feedback
* while the application is downloading and loading.
*
* <p>The download progress bar displays information about
* two different phases of the application:
* the download phase and the initialization phase. </p>
*
* <p>In the <code><mx:Application></code> tag, use the
* the <code>preloader</code> property to specify the name of your subclass.</p>
*
* <p>You can implement a custom download progress bar component
* by creating a subclass of the DownloadProgressBar class.
* Do not implement a download progress bar as an MXML component
* because it loads too slowly.</p>
*
* @see mx.core.Application
* @see mx.preloaders.IPreloaderDisplay
* @see mx.preloaders.Preloader
*/
public class PreloadProgressBar extends Sprite implements IPreloaderDisplay
{
//include "../core/Version.as";
//--------------------------------------------------------------------------
//
// Constructor
//
//--------------------------------------------------------------------------
/**
* Constructor
*/
public function PreloadProgressBar()
{
super();
logoLoader = new Loader();
}
//--------------------------------------------------------------------------
//
// Variables
//
//--------------------------------------------------------------------------
// logo loader
private var logoLoader:flash.display.Loader;
protected var logoUrl:String = "themes/Outsmart_Flex_Preloading_Graphic.swf";
protected var borderFillColor:uint = 0xFFFFFF;
protected var borderFillAlpha:Number = 1.0;
protected var progressBarColors:Array = [ 0xCCCCCC , 0xCCCCCC ];
/**
* The minimum number of milliseconds
* that the display should appear visible.
* If the downloading and initialization of the application
* takes less time than this value, then Flex pauses for this amount
* of time before dispatching the <code>complete</code> event.
*
* @default 0
*/
protected var MINIMUM_DISPLAY_TIME:int = 2000;
/**
* The percentage of the progress bar that the downloading phase
* fills when the SWF file is fully downloaded.
* The rest of the progress bar is filled during the initializing phase.
* This should be a value from 0 to 100.
*
* @default 60
*/
protected var DOWNLOAD_PERCENTAGE:uint = 60;
private var _linkButton:PreloadLinkButton;
/**
* @private
*/
private var _showProgressBar:Boolean = true;
/**
* @private
* Cached Rectangle returned by the labelRect getter.
*/
private var _labelRect:Rectangle = labelRect;
/**
* @private
* Cached Rectangle returned by the linkButtonRect getter.
*/
private var _linkButtonRect:Rectangle = linkButtonRect;
/**
* @private
* Cached Rectangle returned by the percentRect getter.
*/
private var _percentRect:Rectangle = percentRect;
/**
* @private
* Cached RoundedRectangle returned by the borderRect getter.
*/
private var _borderRect:RoundedRectangle = borderRect;
/**
* @private
* Cached RoundedRectangle returned by the barFrameRect getter.
*/
private var _barFrameRect:RoundedRectangle = barFrameRect;
/**
* @private
* Cached RoundedRectangle returned by the barRect getter.
*/
private var _barRect:RoundedRectangle = barRect;
/**
* @private
*/
private var _xOffset:Number = 20;
/**
* @private
*/
private var _yOffset:Number = 20;
/**
* @private
*/
private var _maximum:Number = 0;
/**
* @private
*/
private var _value:Number = 0;
/**
* @private
*/
private var _barSprite:Sprite;
/**
* @private
*/
private var _barFrameSprite:Sprite;
/**
* @private
*/
private var _labelObj:TextField;
/**
* @private
*/
private var _percentObj:TextField;
/**
* @private
*/
private var _startTime:int;
/**
* @private
*/
private var _displayTime:int;
/**
* @private
*/
private var _startedLoading:Boolean = false;
/**
* @private
*/
private var _startedInit:Boolean = false;
/**
* @private
*/
private var _showingDisplay:Boolean = false;
/**
* @private
*/
private var _displayStartCount:uint = 0;
/**
* @private
*/
private var _initProgressCount:uint = 0;
/**
* @private
*/
private var _initProgressTotal:uint = 12;
//--------------------------------------------------------------------------
//
// Overridden properties
//
//--------------------------------------------------------------------------
//----------------------------------
// visible
//----------------------------------
/**
* @private
* Storage for the visible property.
*/
private var _visible:Boolean = false;
/**
* Specifies whether the download progress bar is visible.
*
* <p>When the Preloader control determines that the progress bar should be displayed,
* it sets this value to <code>true</code>. When the Preloader control determines that
* the progress bar should be hidden, it sets the value to <code>false</code>.</p>
*
* <p>A subclass of the DownloadProgressBar class should never modify this property.
* Instead, you can override the setter method to recognize when
* the Preloader control modifies it, and perform any necessary actions. </p>
*
* @default false
*/
override public function get visible():Boolean
{
return _visible;
}
/**
* @private
*/
override public function set visible(value:Boolean):void
{
if (!_visible && value)
show();
else if (_visible && !value )
hide();
_visible = value;
}
//--------------------------------------------------------------------------
//
// Properties: IPreloaderDisplay
//
//--------------------------------------------------------------------------
//----------------------------------
// backgroundAlpha
//----------------------------------
/**
* @private
* Storage for the backgroundAlpha property.
*/
private var _backgroundAlpha:Number = 1;
/**
* Alpha level of the SWF file or image defined by
* the <code>backgroundImage</code> property, or the color defined by
* the <code>backgroundColor</code> property.
* Valid values range from 0 to 1.0.
*
* <p>You can specify either a <code>backgroundColor</code>
* or a <code>backgroundImage</code>, but not both.</p>
*
* @default 1.0
*
*/
public function get backgroundAlpha():Number
{
if (!isNaN(_backgroundAlpha))
return _backgroundAlpha;
else
return 1;
}
/**
* @private
*/
public function set backgroundAlpha(value:Number):void
{
_backgroundAlpha = value;
}
//----------------------------------
// backgroundColor
//----------------------------------
/**
* @private
* Storage for the backgroundColor property.
*/
private var _backgroundColor:uint;
/**
* Background color of a download progress bar.
* You can have either a <code>backgroundColor</code> or a
* <code>backgroundImage</code>, but not both.
*/
public function get backgroundColor():uint
{
return _backgroundColor;
}
/**
* @private
*/
public function set backgroundColor(value:uint):void
{
_backgroundColor = value;
}
//----------------------------------
// backgroundImage
//----------------------------------
/**
* @private
* Storage for the backgroundImage property.
*/
private var _backgroundImage:Object;
/**
* The background image of the application,
* which is passed in by the preloader.
* You can specify either a <code>backgroundColor</code>
* or a <code>backgroundImage</code>, but not both.
*
* <p>A value of null means "not set".
* If this style and the <code>backgroundColor</code> style are undefined,
* the component has a transparent background.</p>
*
* <p>The preloader does not display embedded images.
* You can only use images loaded at runtime.</p>
*
* @default null
*/
public function get backgroundImage():Object
{
return _backgroundImage;
}
/**
* @private
*/
public function set backgroundImage(value:Object):void
{
_backgroundImage = value;
}
//----------------------------------
// backgroundSize
//----------------------------------
/**
* @private
* Storage for the backgroundSize property.
*/
private var _backgroundSize:String = "";
/**
* Scales the image specified by <code>backgroundImage</code>
* to different percentage sizes.
* A value of <code>"100%"</code> stretches the image
* to fit the entire component.
* To specify a percentage value, you must include the percent sign (%).
* A value of <code>"auto"</code>, maintains
* the original size of the image.
*
* @default "auto"
*/
public function get backgroundSize():String
{
return _backgroundSize;
}
/**
* @private
*/
public function set backgroundSize(value:String):void
{
_backgroundSize = value;
}
//----------------------------------
// preloader
//----------------------------------
/**
* @private
* Storage for the preloader property.
*/
private var _preloader:Sprite;
/**
* The Preloader class passes in a reference to itself to the display class
* so that it can listen for events from the preloader.
*/
public function set preloader(value:Sprite):void
{
_preloader = value;
value.addEventListener(ProgressEvent.PROGRESS, progressHandler);
value.addEventListener(Event.COMPLETE, completeHandler);
value.addEventListener(RSLEvent.RSL_PROGRESS, rslProgressHandler);
value.addEventListener(RSLEvent.RSL_COMPLETE, rslCompleteHandler);
value.addEventListener(RSLEvent.RSL_ERROR, rslErrorHandler);
value.addEventListener(FlexEvent.INIT_PROGRESS, initProgressHandler);
value.addEventListener(FlexEvent.INIT_COMPLETE, initCompleteHandler);
}
//----------------------------------
// stageHeight
//----------------------------------
/**
* @private
* Storage for the stageHeight property.
*/
private var _stageHeight:Number = 375;
/**
* The height of the stage,
* which is passed in by the Preloader class.
*/
public function get stageHeight():Number
{
return _stageHeight;
}
/**
* @private
*/
public function set stageHeight(value:Number):void
{
_stageHeight = value;
}
//----------------------------------
// stageWidth
//----------------------------------
/**
* @private
* Storage for the stageHeight property.
*/
private var _stageWidth:Number = 500;
/**
* The width of the stage,
* which is passed in by the Preloader class.
*/
public function get stageWidth():Number
{
return _stageWidth;
}
/**
* @private
*/
public function set stageWidth(value:Number):void
{
_stageWidth = value;
}
//--------------------------------------------------------------------------
//
// Properties
//
//--------------------------------------------------------------------------
//----------------------------------
// barFrameRect
//----------------------------------
/**
* The dimensions of the progress bar border.
* This is a read-only property which you must override
* if you need to change it.
*/
protected function get barFrameRect():RoundedRectangle
{
return new RoundedRectangle(92, 50, 204, 4);
}
//----------------------------------
// barRect
//----------------------------------
/**
* The dimensions of the progress bar.
* This is a read-only property which you must override
* if you need to change it.
*/
protected function get barRect():RoundedRectangle
{
return new RoundedRectangle(92, 49, 204, 6, 0);
}
//----------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -