自制FLEX加载界面

前几天为做一个flex的加载界面,试了很多方法,有用flex组件,有用flash,结果都无果而终,后来经一位高手提示,做了一个偷懒的办法,就是用scaleX来改变进度条图片的长度, HOHO,还是挺有效的,在此给那些个为做loading界面的同志们提供一个解决方案,代码如下:
引用

package
{
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.text.TextField;
import flash.text.TextFormat;

import mx.events.FlexEvent;
import mx.preloaders.DownloadProgressBar;

public class LoadingProgressBar extends DownloadProgressBar
{
private var logo:Loader;
private var logo_bar:Loader;
private var txt:TextField;
private var _preloader:Sprite;
public function LoadingProgressBar()
{
logo = new Loader();
logo.load(new URLRequest("images/loading/loadingPage.jpg"));
addChild(logo);
logo_bar = new Loader();
logo_bar.load(new URLRequest("images/loading/full.png"));
addChild(logo_bar);
super();
}
override public function set preloader(value:Sprite):void{
_preloader = value
_preloader.addEventListener(ProgressEvent.PROGRESS,load_progress);
_preloader.addEventListener(Event.COMPLETE,load_complete);
_preloader.addEventListener(FlexEvent.INIT_PROGRESS,init_progress);
_preloader.addEventListener(FlexEvent.INIT_COMPLETE,init_complete);

stage.addEventListener(Event.RESIZE,resize)
resize(null);
}
private function remove():void{
_preloader.removeEventListener(ProgressEvent.PROGRESS,load_progress);
_preloader.removeEventListener(Event.COMPLETE,load_complete);
_preloader.removeEventListener(FlexEvent.INIT_PROGRESS,init_progress);
_preloader.removeEventListener(FlexEvent.INIT_COMPLETE,init_complete);
stage.removeEventListener(Event.RESIZE,resize)
}
private function resize(e:Event):void{
logo.x = 0;
logo.y = 0;
logo_bar.x = 355;
logo_bar.y = 517;
logo_bar.scaleX = 0.1;

graphics.clear();
graphics.beginFill(0x333333);
graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
graphics.endFill();
}
private function load_progress(e:ProgressEvent):void{

logo_bar.scaleX = Number(e.bytesLoaded/e.bytesTotal);

}
private function load_complete(e:Event):void{

}
private function init_progress(e:FlexEvent):void{

}
private function init_complete(e:FlexEvent):void{

remove()
dispatchEvent(new Event(Event.COMPLETE))
}
}
}


其中logo是一个底图,这个底图包含了进度条外框,而后面那个logo_bar呢,是进度条中间那个条条满的状态,之后就是控制这个条条的位置和底图上的进度条外框结合,控制这个条条的scaleX来设置进度条的长度。

PS:此处代码参考了网上一些解决办法,在此先谢谢那些给予代码参考的人士,然后在此谢谢Flash开发者交流会群里高手们的帮助,还有black,差点被我弄得抓狂了

你可能感兴趣的:(.net,Flex,Flash)