flex默认的preloader已经很不错了,可是有时候还是需要自定义的.
需要在要出现自定义预加载的程序的<mx:Application>标签里加入preloader="".
preloader="com.lichen.component.CustomPreloader"
其中,com.lichen.component是我的包名,CustomPreloader这个类是继承了DownloadProgressBar
这句就是指明了程序preloader的时候加载哪个类
CustomPreloader.as
package com.lichen.component
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.text.TextField;
import flashx.textLayout.BuildInfo;
import mx.events.*;
import mx.preloaders.DownloadProgressBar;
public class CustomPreloader extends DownloadProgressBar {
public var wcs:WelcomeScreen;
public var msg:TextField;
public function CustomPreloader()
{
super();
msg=new TextField();
wcs = new WelcomeScreen();
this.addChild(wcs);
this.addChild(msg);
}
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 );
}
private function SWFDownloadProgress( event:ProgressEvent ):void {
msg.text=String(int(event.bytesLoaded/event.bytesTotal*100))+" %";
msg.background=true;
msg.backgroundColor=0xD4E4FF;
msg.width=200;
msg.height=20;
msg.textColor=0x444444;
}
private function SWFDownloadComplete( event:Event ):void {}
private function FlexInitProgress( event:Event ):void {
// wcs.ready = true;
msg.text="完成了!";
wcs.closeScreen();
dispatchEvent(new Event(Event.COMPLETE));
}
private function FlexInitComplete( event:Event ):void
{
// wcs.ready = true;
// dispatchEvent( new Event( Event.COMPLETE ) );
}
}
}
这其中使用了WelcomeScreen,这个类的作用是使用图片,并且设置定时器控制图片显示的alpha属性.
WelcomeScreen.as
package com.lichen.component
{
import flash.display.Loader;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.ByteArray;
import flash.utils.Timer;
public class WelcomeScreen extends Loader
{
[ Embed(source="images/mt.jpg", mimeType="application/octet-stream") ]
public var WelcomeScreenGraphic:Class;
public var timer:Timer;
private var fadeInRate:Number = .05;
private var fadeOutRate:Number = .08;
private var timeAutoClose:int = 500;
public var ready:Boolean = false;
public function WelcomeScreen()
{
this.visible = false;
this.alpha = 0.5;
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( this.alpha < 1) this.alpha = this.alpha + this.fadeInRate;
if( this.stage.stageWidth>0){
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;
}
if( this.ready && timer.currentCount > this.timeAutoClose ) closeScreen()
}
public function closeScreen():void
{
timer.removeEventListener( TimerEvent.TIMER, updateView );
timer.removeEventListener( MouseEvent.MOUSE_DOWN, mouseDown);
timer.addEventListener( TimerEvent.TIMER, closeScreenFade );
}
public function closeScreenFade( event:TimerEvent ):void
{
if( this.alpha > 0){
this.alpha = this.alpha - fadeOutRate;
} else {
timer.stop()
this.parent.removeChild(this);
}
}
public function mouseDown( event:MouseEvent ):void
{
closeScreen();
}
}
}
最终的效果图

- 大小: 194.5 KB
分享到:
相关推荐
在“flex自定义加载进度条”的场景中,开发者可能想要替换Flex默认的Application预加载器,以提供更个性化的用户体验。自定义预加载器可以让开发者自由设计加载界面的外观和交互,例如改变颜色、形状或动画效果,...
在Flex应用程序开发中,用户首次启动应用时会看到一个加载屏幕,这个屏幕通常被称为预加载器(Preloader)。预加载器的主要目的是显示应用程序加载的进度,同时为用户提供一种视觉反馈,让他们知道程序正在准备运行...
在网页设计中,预加载器动画(PreLoader Animation)是一种重要的用户体验优化技术,尤其是在处理大容量内容或复杂交互的网站中。预加载器是页面在完全加载之前展示的一个视觉反馈,它告诉用户页面正在准备就绪,...
压缩包中的文件名“simple_preloader_2307”可能是一个简单的预加载器(preloader)示例。在Flex应用中,预加载器是加载应用程序的主要组件,它在主应用程序完全加载之前显示进度,以提高用户体验。这个文件可能是用...
通过研究和修改这个“BRUSHED METAL PRELOADER”源码,开发者可以学习到如何创建自定义、交互式的预加载器,并将其应用于自己的Flash MX或Flex项目中,提升网站的用户体验。同时,这也是一个深入了解ActionScript...
首先,`Preloader.as` 是一个常见的Flex组件,它负责在应用程序加载之前显示进度条,提高用户体验。在处理桌面背景这样的任务时,可能用到预加载器来确保所有必要的资源(如图片或皮肤)在改变桌面背景前已完全加载...
Flex应用的根对象是SystemManager,这是一个Display Class,继承自flash.display.MovieClip,使得预加载器(Preloader)和应用程序(Application)可以在两个不同的帧中运行。SystemManager有一个...