Flex Preloader

在网上看到好多关于flex preloader,但是有的不是很理想,其中有一个加载flash的,组件都初始化结束了,那flash还在那里动.
最近也用到这个preloader,把它改造了一下,加载完flash后在显示组件,


package com.preload
{
import flash.display.Loader;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.geom.Point;
import flash.utils.ByteArray;
import flash.utils.Timer;

public class WelcomeScreen extends Loader
{

[Embed(source="../asserts/welcome.swf", mimeType="application/octet-stream")]
public var WelcomeScreenGraphic : Class;
public var timer : Timer;
private var fadeInRate : Number = .01;
private var fadeOutRate : Number = .02;
private var timeAutoClose : int = 100;
public var ready : Boolean = false;
public var COMPLETE_EVENT : String = "complete";
private var completeFlag : Boolean = true;


public function WelcomeScreen()
{
this.visible = false;
this.alpha = 0;
timer = new Timer(1);
timer.addEventListener(TimerEvent.TIMER, updateView);
timer.start();
this.loadBytes(new WelcomeScreenGraphic() as ByteArray);
//this.addEventListener( MouseEvent.MOUSE_DOWN, mouseDown );
}

public function updateView(event : TimerEvent):void
{
if(completeFlag)
{
if(this.alpha < 1) this.alpha = this.alpha + this.fadeInRate;
this.stage.addChild(this);
var point : Point = new Point();
this.x = this.stage.stageWidth/2 - this.width/2;
this.y = this.stage.stageHeight/2 - this.height/2;
this.visible=true;
completeFlag = false;
}
if (this.ready && timer.currentCount > this.timeAutoClose)
closeScreen();
}

public function closeScreen():void
{
timer.removeEventListener(TimerEvent.TIMER, updateView);
timer.addEventListener(TimerEvent.TIMER, closeScreenFade);
}

public function closeScreenFade(event : TimerEvent):void
{
timer.stop();
this.parent.removeChild(this);
dispatchEvent(new Event(COMPLETE_EVENT));
}
}
}




package com.preload
{


import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;

import mx.events.*;
import mx.preloaders.DownloadProgressBar;

public class CustomPreloader extends DownloadProgressBar {

public var wcs:WelcomeScreen;

public function CustomPreloader()
{
super();
wcs = new WelcomeScreen();
this.addChild(wcs)
}

override public function set preloader( preloader:Sprite ):void
{
preloader.addEventListener(ProgressEvent.PROGRESS, SWFDownloadProgress);
preloader.addEventListener(Event.COMPLETE, SWFDownloadComplete);
preloader.addEventListener(FlexEvent.INIT_PROGRESS, FlexInitProgress);
preloader.addEventListener(FlexEvent.INIT_COMPLETE, FlexInitComplete);
this.wcs.addEventListener(wcs.COMPLETE_EVENT, wcsComplete);
}

private function SWFDownloadProgress(event : ProgressEvent):void {}

private function SWFDownloadComplete(event : Event):void {}

private function FlexInitProgress(event : Event):void {}

private function FlexInitComplete(event : Event):void
{
wcs.ready = true;
}



private function wcsComplete(event : Event) : void
{
wcs.ready = true;
dispatchEvent(new Event( Event.COMPLETE));
}

}

}

flash动画就不上传了.望大家参考.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值