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

预览: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();        
        }
                
    }
}

转自:http://gdlszxx.gjjblog.com/archives/892823/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值