首页 > 代码库 > loading
loading
第一步:在FLASH CS 5中 制作Loading影片剪辑名称为PreloaderDisplay
如图所示:
第二步:在影片剪辑的第一帧加上如下代码:
setMainProgress(0);
setInitalizeProgress(0);
percentTxt.text="0%";
function setMainProgress(percent:Number):void {
ProgBar.width = percent * 325;
}
function setInitalizeProgress(percent:Number):void {
ProgBar.width = percent * 325;
}
第三步:将影片剪辑打包成SWC放入FLEX工程lib包下
第四步:在flex工程里编写如下类
package com.uitls
{
import mx.preloaders.SparkDownloadProgressBar;
public class DocumentManagerPreloaderBar extends SparkDownloadProgressBar
{
private var spreLoader:PreloaderDisplay;
public function DocumentManagerPreloaderBar()
{
super();
}
override protected function createChildren():void{
if(!spreLoader){
spreLoader = new PreloaderDisplay();
var sX:Number = Math.round((stage.stageWidth-spreLoader.width)/2);
var sY:Number = Math.round((stage.stageHeight-spreLoader.height)/2);
spreLoader.x = sX;
spreLoader.y = sY;
this.addChild(spreLoader);
}
}
override protected function setDownloadProgress(completed:Number, total:Number):void{
if(spreLoader){
spreLoader.setMainProgress(completed/total);
setPreloaderLoadingText(Math.round((completed/total)*100).toString() + "%");
}
}
override protected function setInitProgress(completed:Number, total:Number):void{
if(spreLoader){
spreLoader.setInitalizeProgress(completed/total);
if(completed>=total){
setPreloaderLoadingText("OVER");
}else{
//setPreloaderLoadingText("initializing " + completed + " of " + total);
setPreloaderLoadingText(Math.round((completed/total)*100).toString() + "%");
}
}
}
private function setPreloaderLoadingText(str:String):void{
spreLoader.percentTxt.text = str;
}
}
}
第五步:在Flex Application中加上 preloader="com.uitls.DocumentManagerPreloaderBar"
第六步:测试,完成。
loading