现在的位置: 首页 > 综合 > 正文

一个flex例子(自定义download progress bar的)

2012年08月15日 ⁄ 综合 ⁄ 共 2724字 ⁄ 字号 评论关闭
地址http://www.onflex.org/flexapps/components/CustomPreloader/

代码

package preload
{
    import flash.display.Loader;
    import flash.utils.ByteArray;
    import flash.events.MouseEvent;
    import flash.events.TimerEvent;
    import flash.utils.Timer;
    
    
public class WelcomeScreen extends Loader//继承其他类吧???
    {
        
        [ Embed(source
="welcome.gif", mimeType="application/octet-stream") ]//要求这个progress bar加载前,先把welcome.gif下载好,以便代码之用
        public var WelcomeGif:Class;//建立一个空类
        public var timer:Timer;//建立一个定时器
        private var fadeInRate:Number  = .01;//设定透明度每次增加的量
        private var fadeOutRate:Number = .02;//设定透明度每次减少的量
        private var timeAutoClose:int = 500;
        
public var ready:Boolean = false
        
        
public function WelcomeScreen()//本类的构造函数,在实例化的时候首先执行
        {
            
this.visible = false;//不显示
            this.alpha = 0;//完全透明
            timer = new Timer( 1 );//建立定时器,时间间隔为1毫秒??
            timer.addEventListener( TimerEvent.TIMER, updateView );//建立一个显示的过程
            timer.start();

            this.loadBytes( new WelcomeGif() as ByteArray );//把图片load进实例化为ByteArray的WelcomeGif类里面,详细看loadBytes的用法(这句应该是属于显示图片的关键语句吧)
            this.addEventListener( MouseEvent.MOUSE_DOWN, mouseDown );//建立鼠标帧听时间(实现点击鼠标就关闭???)             
        }
        
        
public function updateView( event:TimerEvent ):void//图片从全透明变成不透明的方法
        {
            
ifthis.alpha < 1)    this.alpha = this.alpha + this.fadeInRate;
            
this.stage.addChild(this)
            
this.x = this.stage.stageWidth/2 - this.width/2
            
this.y = this.stage.stageHeight/2 - this.height/2
            
this.visible=true;
            
ifthis.ready && timer.currentCount > this.timeAutoClose ) closeScreen()    //如果ready为true??与定时器的值大于上面设置的500,就关闭图片
        }
        
        
public function closeScreen():void//关闭图片的方法,去掉2个帧听,加入一个新的帧听,让图片渐渐消失
        {
            timer.removeEventListener( TimerEvent.TIMER, updateView );
            timer.removeEventListener( MouseEvent.MOUSE_DOWN, mouseDown);
            timer.addEventListener( TimerEvent.TIMER, closeScreenFade );                    
        }
        
        
public function closeScreenFade( event:TimerEvent ):void//图片渐渐消失的过程,透明度不断变小,当透明度不大于0(就是为0时),timer停止,图片被去掉
        {
            
ifthis.alpha > 0){
                
this.alpha = this.alpha - fadeOutRate;
            } 
else {
                timer.stop()
                
this.parent.removeChild(this);
            }        
        }        
        
        
public function mouseDown( event:MouseEvent ):void//这里简单,老鼠一点,就关闭了
        {
            closeScreen();        
        }
                
    }
}

注释的不一定准确,发现错误,欢迎指正...
这是主要的类,其他的比较简单,详细可以打开连接后,右击,点ViewSource...

欢迎有共同兴趣的一起研究,请联系:QQ165619258,MSN:gd_gz_boy@hotmail.com

抱歉!评论已关闭.