在网上看到好多关于flex preloader,但是有的不是很理想,其中有一个加载flash的,组件都初始化结束了,那flash还在那里动.
最近也用到这个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动画就不上传了.望大家参考.