`

MyDownloadProgressBar.as

    博客分类:
  • Flex
阅读更多
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();
            }
        }
    }
}
分享到:
评论

相关推荐

    基于三层感知机实现手写数字识别-内含源码和说明书.zip

    基于三层感知机实现手写数字识别-内含源码和说明书.zip

    setuptools-40.7.0.zip

    Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。

    搭建VGG16神经网络实现图像分类-内含源码和说明书.zip

    搭建VGG16神经网络实现图像分类-内含源码和说明书.zip

    setuptools-40.6.1.zip

    Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。

    华为OD机试D卷 - 判断字符串子序列 - 免费看解析和代码.html

    私信博主免费获取真题解析以及代码

    安享智慧理财测试项目Mock服务代码

    安享智慧理财测试项目Mock服务代码

    基于STM32单片机的智能晾衣架.zip

    基于单片机的系统

    Mamba selective-scan-cuda-linux-gnu.so

    安装成功后,还是遇到ImportError xxxx selective_scan_cuda.cpython-xxx-linux-gnu.so undefined symbol,用此编译好的文件进行替换即可

    基于Java EE的停车场管理系统.zip

    如今,我国现代化发展迅速,人口比例急剧上升,在一些大型的商场,显得就格外拥挤,私家车的数量越来越多,商场停车难得问题凸显,对于停车场的合理利用有助于缓解用户停车压力,鉴于这样的背景;初步设定系统功能主要包括,用户信息管理,违规车辆信息管理,刷卡停车牌管理,停车位信息管理,停车计费,信息查看管理等功能模块。本系统采用JAVAEE开发形式,利用数据库来完成数据存储功能,运用了B/S形式的开发模式,严格按照了软件工程的开发模式进行开发,保证系统的良好运行。

    华为OD机试D卷 - 免单统计 - 免费看解析和代码.html

    私信博主免费获取真题解析以及代码

    setuptools-2.2.tar.gz

    Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。

    ASP.NET《数据库原理及应用技术》课程指导平台的开发(源代码)

    ASP.NET《数据库原理及应用技术》课程指导平台的开发(源代码)

    setuptools-40.4.2.zip

    Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。

    setuptools-54.0.0-py3-none-any.whl

    Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。

    基于SpringBoot+Hadoop的评价预测系统的设计与实现+部署文档+全部资料 高分项目.zip

    【资源说明】 基于SpringBoot+Hadoop的评价预测系统的设计与实现+部署文档+全部资料 高分项目.zip基于SpringBoot+Hadoop的评价预测系统的设计与实现+部署文档+全部资料 高分项目.zip 【备注】 1、该项目是个人高分项目源码,已获导师指导认可通过,答辩评审分达到95分 2、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 3、本项目适合计算机相关专业(人工智能、通信工程、自动化、电子信息、物联网等)的在校学生、老师或者企业员工下载使用,也可作为毕业设计、课程设计、作业、项目初期立项演示等,当然也适合小白学习进阶。 4、如果基础还行,可以在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 欢迎下载,沟通交流,互相学习,共同进步!

    利用python的pyautogui函数实现简单的自动化操作

    1.安装python3.4以上版本,并配置环境变量(目前有装3.9遇到坑的,我个人用的3.7.6) 教程:https://www.runoob.com/python3/python3-install.html 2.安装依赖包 方法:在cmd中(win+R 输入cmd 回车)输入 pip install pyperclip 回车 pip install xlrd 回车 pip install pyautogui==0.9.50 回车 pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple 回车 pip install pillow 回车 这几步如果哪步没成功,请自行百度 如 pip install opencv-python失败 3.把每一步要操作的图标、区域截图保存至本文件夹 png格式(注意如果同屏有多个相同图标,回默认找到最左上的一个,因此怎么截图,截多大的区域,是个学问,如输入框只截中间空白部分肯定是不行的,宗旨就是“唯一”) 4.在cmd.xls 的sheet1 中,配置每一步的指令,如指

    setuptools-8.0.4.tar.gz

    Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。

    setuptools-18.7.1.zip

    Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。

    setuptools-20.6.7.zip

    Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。

    华为OD机试D卷 - 数据单元的变化替换 - 免费看解析和代码.html

    私信博主免费获取真题解析以及代码

Global site tag (gtag.js) - Google Analytics