- 浏览: 77441 次
- 性别:
- 来自: 大连
最新评论
http://www.pixelbox.net/demos/downloadProgressBar/MyDownloadProgressBar.as
package com.example.preloaders
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.events.TimerEvent;
import flash.geom.Rectangle;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.utils.Timer;
import flash.utils.getTimer;
import mx.events.FlexEvent;
import mx.preloaders.IPreloaderDisplay;
public class MyDownloadProgressBar extends Sprite implements IPreloaderDisplay
{
// Settings fiddle with these as you like
private var _minimumDuration:Number = 3000; // even if the preloader is done, take this long to "finish"
// Implementation variables, used to make everything work properly
private var _IsInitComplete : Boolean = false;
private var _timer : Timer; // this is so we can redraw the progress bar
private var _bytesLoaded : uint = 0;
private var _bytesExpected : uint = 1; // we start at 1 to avoid division by zero errors.
private var _fractionLoaded : Number = 0; // Will be used for the width of the loading bar
private var _preloader : Sprite;
private var _currentStatus : String; // The current stats of the application, downloaded, initilising etc
// Display properties of the loader, these are set in the mx:Application tag
private var _backgroundColor : uint = 0x000000;
private var _stageHeight : Number = 1;
private var _stageWidth : Number = 1;
private var _loadingBarColour : uint = 0x3ea1ee;
// Display elements
private var _loadingBar : Rectangle; // The loading bar that will be drawn
private var loadingImage : flash.display.Loader;
private var progressText : TextField;
private var statusText : TextField;
public function MyDownloadProgressBar()
{
super();
}
// Called when the appication is ready for the preloading screen
public function initialize():void
{
drawBackground();
// Load in your logo or loading image
loadingImage = new flash.display.Loader();
loadingImage.contentLoaderInfo.addEventListener( Event.COMPLETE, loader_completeHandler);
loadingImage.load(new URLRequest("../assets/loadingLogo.jpg")); // This path needs to be relative to your swf on the server, you could use an absolute value if you are unsure
}
private function loader_completeHandler(event:Event):void
{
// At this stage we are sure the image has loaded so we can start drawing the progress bar and other info
// Draw the loading image
addChild(loadingImage);
loadingImage.width = 200;
loadingImage.height= 100;
loadingImage.x = 400;
loadingImage.y = 200;
// Draw your loading bar in it's full state - x,y,width,height
_loadingBar = new Rectangle(400, 300, 200, 10);
// Create a text area for your progress text
progressText = new TextField();
progressText.x = 400;
progressText.y = 310;
progressText.width = 200;
progressText.height = 20;
progressText.textColor = 0x3ea1ee;
addChild(progressText);
// Create a text area for your status text
statusText = new TextField();
statusText.x = 400;
statusText.y = 320;
statusText.width = 200;
statusText.height = 20;
statusText.textColor = 0x3ea1ee;
addChild(statusText);
// The first change to this var will be Download Complete
_currentStatus = 'Downloading';
// Start a timer to redraw your loading elements frequently
_timer = new Timer(50);
_timer.addEventListener(TimerEvent.TIMER, timerHandler);
_timer.start();
}
// This is called repeatidly untill we are finished loading
private function draw():void
{
graphics.beginFill( _loadingBarColour , 1);
graphics.drawRect(_loadingBar.x, _loadingBar.y, _loadingBar.width * _fractionLoaded, _loadingBar.height);
graphics.endFill();
progressText.text = (Math.round(_bytesLoaded / 1024)).toString() + 'KB of ' + (Math.round(_bytesExpected / 1024)) + 'KB downloaded';
statusText.text = _currentStatus;
}
private function drawBackground():void
{
// Draw the background using the background colour (set in the mx:Application MXML tag)
graphics.beginFill( _backgroundColor, 1);
graphics.drawRect( 0, 0, stageWidth, stageHeight);
graphics.endFill();
}
// This code comes from DownloadProgressBar. I have modified it to remove some unused event handlers.
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);
}
// Getters and setters for values, most are set via the MXML in the mx:Application tag
public function set backgroundAlpha(alpha:Number):void{}
public function get backgroundAlpha():Number { return 1; }
public function set backgroundColor(color:uint):void { _backgroundColor = color; }
public function get backgroundColor():uint { return _backgroundColor; }
public function set backgroundImage(image:Object):void {}
public function get backgroundImage():Object { return null; }
public function set backgroundSize(size:String):void {}
public function get backgroundSize():String { return "auto"; }
public function set stageHeight(height:Number):void { _stageHeight = height; }
public function get stageHeight():Number { return _stageHeight; }
public function set stageWidth(width:Number):void { _stageWidth = width; }
public function get stageWidth():Number { return _stageWidth; }
//--------------------------------------------------------------------------
//
// Event handlers
//
//--------------------------------------------------------------------------
// Called by the application as the download progresses.
private function progressHandler(event:ProgressEvent):void
{
_bytesLoaded = event.bytesLoaded;
_bytesExpected = event.bytesTotal;
_fractionLoaded = Number(_bytesLoaded) / Number(_bytesExpected);
}
// Called when the download is complete
private function completeHandler(event:Event):void
{
_currentStatus = 'Download Completed';
trace(_currentStatus);
}
// Called by the application as the initilisation progresses.
private function initProgressHandler(event:Event):void
{
if( !_IsInitComplete) // This seems to be called right at the end for some reason, so this stopps it if the app is already complete
{
_currentStatus = 'Initilising Application';
trace(_currentStatus);
}
}
// Called when both download and initialisation are complete
private function initCompleteHandler(event:Event):void
{
_currentStatus = 'Initilisation Completed';
trace(_currentStatus);
_IsInitComplete = true;
}
// Called as often as possible
private function timerHandler(event:Event):void
{
if ( _IsInitComplete && getTimer() > _minimumDuration )
{
// Everything is now ready, so we can tell the application to show the main application
// NOTE: If you have set a min duration, your application may already have started running
_timer.stop();
_timer.removeEventListener(TimerEvent.TIMER,timerHandler);
dispatchEvent(new Event(Event.COMPLETE));
}
else
{
// Update the screen with the latest progress
draw();
}
}
}
}
package com.example.preloaders
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.events.TimerEvent;
import flash.geom.Rectangle;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.utils.Timer;
import flash.utils.getTimer;
import mx.events.FlexEvent;
import mx.preloaders.IPreloaderDisplay;
public class MyDownloadProgressBar extends Sprite implements IPreloaderDisplay
{
// Settings fiddle with these as you like
private var _minimumDuration:Number = 3000; // even if the preloader is done, take this long to "finish"
// Implementation variables, used to make everything work properly
private var _IsInitComplete : Boolean = false;
private var _timer : Timer; // this is so we can redraw the progress bar
private var _bytesLoaded : uint = 0;
private var _bytesExpected : uint = 1; // we start at 1 to avoid division by zero errors.
private var _fractionLoaded : Number = 0; // Will be used for the width of the loading bar
private var _preloader : Sprite;
private var _currentStatus : String; // The current stats of the application, downloaded, initilising etc
// Display properties of the loader, these are set in the mx:Application tag
private var _backgroundColor : uint = 0x000000;
private var _stageHeight : Number = 1;
private var _stageWidth : Number = 1;
private var _loadingBarColour : uint = 0x3ea1ee;
// Display elements
private var _loadingBar : Rectangle; // The loading bar that will be drawn
private var loadingImage : flash.display.Loader;
private var progressText : TextField;
private var statusText : TextField;
public function MyDownloadProgressBar()
{
super();
}
// Called when the appication is ready for the preloading screen
public function initialize():void
{
drawBackground();
// Load in your logo or loading image
loadingImage = new flash.display.Loader();
loadingImage.contentLoaderInfo.addEventListener( Event.COMPLETE, loader_completeHandler);
loadingImage.load(new URLRequest("../assets/loadingLogo.jpg")); // This path needs to be relative to your swf on the server, you could use an absolute value if you are unsure
}
private function loader_completeHandler(event:Event):void
{
// At this stage we are sure the image has loaded so we can start drawing the progress bar and other info
// Draw the loading image
addChild(loadingImage);
loadingImage.width = 200;
loadingImage.height= 100;
loadingImage.x = 400;
loadingImage.y = 200;
// Draw your loading bar in it's full state - x,y,width,height
_loadingBar = new Rectangle(400, 300, 200, 10);
// Create a text area for your progress text
progressText = new TextField();
progressText.x = 400;
progressText.y = 310;
progressText.width = 200;
progressText.height = 20;
progressText.textColor = 0x3ea1ee;
addChild(progressText);
// Create a text area for your status text
statusText = new TextField();
statusText.x = 400;
statusText.y = 320;
statusText.width = 200;
statusText.height = 20;
statusText.textColor = 0x3ea1ee;
addChild(statusText);
// The first change to this var will be Download Complete
_currentStatus = 'Downloading';
// Start a timer to redraw your loading elements frequently
_timer = new Timer(50);
_timer.addEventListener(TimerEvent.TIMER, timerHandler);
_timer.start();
}
// This is called repeatidly untill we are finished loading
private function draw():void
{
graphics.beginFill( _loadingBarColour , 1);
graphics.drawRect(_loadingBar.x, _loadingBar.y, _loadingBar.width * _fractionLoaded, _loadingBar.height);
graphics.endFill();
progressText.text = (Math.round(_bytesLoaded / 1024)).toString() + 'KB of ' + (Math.round(_bytesExpected / 1024)) + 'KB downloaded';
statusText.text = _currentStatus;
}
private function drawBackground():void
{
// Draw the background using the background colour (set in the mx:Application MXML tag)
graphics.beginFill( _backgroundColor, 1);
graphics.drawRect( 0, 0, stageWidth, stageHeight);
graphics.endFill();
}
// This code comes from DownloadProgressBar. I have modified it to remove some unused event handlers.
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);
}
// Getters and setters for values, most are set via the MXML in the mx:Application tag
public function set backgroundAlpha(alpha:Number):void{}
public function get backgroundAlpha():Number { return 1; }
public function set backgroundColor(color:uint):void { _backgroundColor = color; }
public function get backgroundColor():uint { return _backgroundColor; }
public function set backgroundImage(image:Object):void {}
public function get backgroundImage():Object { return null; }
public function set backgroundSize(size:String):void {}
public function get backgroundSize():String { return "auto"; }
public function set stageHeight(height:Number):void { _stageHeight = height; }
public function get stageHeight():Number { return _stageHeight; }
public function set stageWidth(width:Number):void { _stageWidth = width; }
public function get stageWidth():Number { return _stageWidth; }
//--------------------------------------------------------------------------
//
// Event handlers
//
//--------------------------------------------------------------------------
// Called by the application as the download progresses.
private function progressHandler(event:ProgressEvent):void
{
_bytesLoaded = event.bytesLoaded;
_bytesExpected = event.bytesTotal;
_fractionLoaded = Number(_bytesLoaded) / Number(_bytesExpected);
}
// Called when the download is complete
private function completeHandler(event:Event):void
{
_currentStatus = 'Download Completed';
trace(_currentStatus);
}
// Called by the application as the initilisation progresses.
private function initProgressHandler(event:Event):void
{
if( !_IsInitComplete) // This seems to be called right at the end for some reason, so this stopps it if the app is already complete
{
_currentStatus = 'Initilising Application';
trace(_currentStatus);
}
}
// Called when both download and initialisation are complete
private function initCompleteHandler(event:Event):void
{
_currentStatus = 'Initilisation Completed';
trace(_currentStatus);
_IsInitComplete = true;
}
// Called as often as possible
private function timerHandler(event:Event):void
{
if ( _IsInitComplete && getTimer() > _minimumDuration )
{
// Everything is now ready, so we can tell the application to show the main application
// NOTE: If you have set a min duration, your application may already have started running
_timer.stop();
_timer.removeEventListener(TimerEvent.TIMER,timerHandler);
dispatchEvent(new Event(Event.COMPLETE));
}
else
{
// Update the screen with the latest progress
draw();
}
}
}
}
相关推荐
setting.xml文件,修改Maven仓库指向至阿里仓
基于java的玉安农副产品销售系统的开题报告
dev-c++ 6.3版本
基于java的项目监管系统开题报告
基于springboot多彩吉安红色旅游网站源码数据库文档.zip
毕业设计&课设_基于 AFLFast 改进能量分配策略的毕业设计项目,含 Mix Schedule策略设计及测试结果分析.zip
基于springboot办公用品管理系统源码数据库文档.zip
C++调用qml对象Demo
非常漂亮的类Web界面的Delphi设计54ed7-main.zip
VB SQL车辆管理系统是一款基于Visual Basic(VB)编程语言和SQL数据库开发的综合车辆管理工具。该系统集成了车辆信息管理、驾驶员信息管理、车辆调度、维修记录、数据存储与检索、报告生成以及安全权限管理等多个核心功能模块。 源代码部分提供了详细的开发流程和实现方法,涵盖了从数据库设计、界面设计到事件驱动编程、数据访问技术和错误处理等关键技术点。通过该系统,用户可以方便地录入、查询、修改和删除车辆及驾驶员信息,实现车辆信息的实时更新和跟踪。同时,系统还支持生成各类车辆管理相关的报告,帮助用户更好地掌握车辆运营情况。 系统部分则采用了直观易用的用户界面设计,使得用户能够轻松上手并快速完成车辆管理工作。系统还具备强大的数据处理能力和安全性,通过数据备份和系统升级优化等功能,确保数据的完整性和系统的稳定运行。 总体而言,VB SQL车辆管理系统是一款功能全面、易于操作且安全可靠的车辆管理工具,适用于企业和个人进行日常车辆运营和管理。无论是车辆信息的录入、查询还是报告生成,该系统都能够提供高效、便捷的服务,是车辆管理工作的理想选择。
AutoSAR基础学习资源
基于springboot英语学习平台源码数据库文档.zip
数据集,深度学习,密封数据集,马体态数据集
基于java的数字家庭网站开题报告
podman使用国内源镜像加速器
基于springboot+web的留守儿童网站源码数据库文档.zip
基于springboot的智能宾馆预定系统源码数据库文档.zip
GetQzonehistory-main.zip
环境说明:开发语言:Java 框架:springboot JDK版本:JDK1.8 服务器:tomcat7 数据库:mysql 5.7 数据库工具:Navicat 开发软件:eclipse/myeclipse/idea Maven包:Maven 浏览器:谷歌浏览器。 项目经过测试均可完美运行
内容概要:本文档详细介绍了QST公司生产的QMI8A01型号的6轴惯性测量单元的数据表及性能参数。主要内容包括设备特性、操作模式、接口标准(SPI、I2C与I3C),以及各种运动检测原理和技术规格。文中还提到了设备的工作温度范围宽广,内置的大容量FIFO可用于缓冲传感器数据,减少系统功耗。此外,对于器件的安装焊接指导亦有详细介绍。 适合人群:电子工程技术人员、嵌入式开发人员、硬件设计师等。 使用场景及目标:适用于需要精准测量物体空间位置变化的应用场合,如消费电子产品、智能穿戴设备、工业自动化等领域。帮助工程师快速掌握该款IMU的技术要点和应用场景。 其他说明:文档提供了详细的电气连接图表、封装尺寸图解等资料,方便用户进行电路板的设计制作。同时针对特定应用提出了一些优化建议。