我真的需要帮助,我已经处理了几个月了。基本上我有一个带有自定义预加载器的旧 Flex 3 应用程序。一旦每个人都升级到 Flash 11 和 11.5,预加载器就消失了。我正在尝试使用 Flash Builder 4.7 进行工作,并在 3.6 库中进行链接,但可惜它似乎默默地失败了。即使是标准的预加载器也与“正在加载库 0”(但它确实显示)结合在一起......我正在使用现在经典的“DownloadProgressBar”扩展自定义预加载器模式。
package com.timberdesignco.preloader
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
import mx.events.FlexEvent;
import mx.preloaders.DownloadProgressBar;
public final class CustomPreloader extends DownloadProgressBar {
public var loader : LoadScreen;
private var _timer : Timer;
public function CustomPreloader()
{
super();
}
override public function initialize() : void
{
super.initialize();
this.loader = new LoadScreen();
this.addChild(this.loader);
this._timer = new Timer(10);
this._timer.addEventListener(TimerEvent.TIMER, handleTimerTick);
this._timer.start();
}
override public function set preloader(preloader : Sprite):void
{
preloader.addEventListener(ProgressEvent.PROGRESS, SWFDownLoadScreen);
preloader.addEventListener(Event.COMPLETE, SWFDownloadComplete);
preloader.addEventListener(FlexEvent.INIT_PROGRESS, FlexInitProgress);
preloader.addEventListener(FlexEvent.INIT_COMPLETE, FlexInitComplete);
}
private function SWFDownLoadScreen(event : ProgressEvent) : void
{
var prog : Number = event.bytesLoaded / event.bytesTotal * 100;
if (this.loader)
{
this.loader.progress = prog;
}
}
private function handleTimerTick(event : TimerEvent) : void
{
this.stage.addChild(this);
this.loader.x = (this.stage.stageWidth - this.loader.width) / 2 - 35;
this.loader.y = (this.stage.stageHeight - this.loader.height) / 2;
this.loader.refresh();
}
private function SWFDownloadComplete(event : Event) : void {}
private function FlexInitProgress(event : Event) : void {}
private function FlexInitComplete(event : Event) : void
{
this.loader.ready = true;
this._timer.stop();
this.dispatchEvent(new Event(Event.COMPLETE));
}
override protected function showDisplayForInit(elapsedTime:int, count:int):Boolean
{
return true;
}
override protected function showDisplayForDownloading(elapsedTime:int,
event:ProgressEvent):Boolean
{
return true;
}
}
}
package com.timberdesignco.preloader
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.display.Loader;
import flash.display.Sprite;
import flash.text.Font;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.utils.ByteArray;
import mx.graphics.codec.PNGEncoder;
public class LoadScreen extends Loader {
//~ Instance Attributes -----------------------------------------------
[Embed(source="/assets/CreightonReg.otf", fontFamily="Creighton")]
private var CreightonEmbedded:Class;
private var creightonEmbeddedFont:Font = new CreightonEmbedded();
[Embed(source="/assets/LoadingBar-Bark.png")]
private var MyLogoClass: Class;
private var _logo : Bitmap;
private var _logoData : BitmapData;
private var isReady : Boolean = false;
public var progress : Number;
//~ Constructor -------------------------------------------------------
public function LoadScreen()
{
super();
this.progress = 0;
this._logo = new MyLogoClass as Bitmap;
}
//~ Methods -----------------------------------------------------------
public function refresh() : void {
this._logoData = this.draw();
var encoder : PNGEncoder = new PNGEncoder();
var bytes : ByteArray = encoder.encode(this._logoData);
this.loadBytes(bytes);
}
override public function get width() : Number {
return 300;
}
override public function get height() : Number {
return 300;
}
private function draw() : BitmapData {
// create bitmap data to create the data
var data : BitmapData = new BitmapData(this.width, this.height, true, 0);
// draw the logo
//data.draw(this._logo.bitmapData, null, null, null, null, true);
// draw the progress bar
var s : Sprite = new Sprite();
var g : Graphics = s.graphics;
// draw the bar background
//g.beginFill(_BarBackground);
//g.lineStyle(2, _BarOuterBorder, 1, true);
//var px : int = (this.width - _BarWidth) / 2;
//var py : int = _TopMargin + _LogoHeight + _Padding;
//g.drawRoundRect(px, py, _BarWidth, _BarHeight, 2);
//var containerWidth : Number = _BarWidth - 4;
//var progWidth : Number = containerWidth * this.progress / 100;
//g.beginFill(_BarColor);
g.lineStyle(2, 0xa1865e);
//g.drawRect(px + 1, py + 1, progWidth, _BarHeight - 3);
var rad:int = (5 * (this.progress / 10));
for(var i:int = this.progress; i > 0; i--) {
g.drawCircle(this.width / 2 + 5, this.height / 2, (5 * (int)(i / 10) + 1));
data.draw(this._logo.bitmapData, null, null, null, null, true);
}
var startX:Number = this.width / 2 + 5;
var endX:Number = startX + 50;//(rad / 2);
var startY:Number = (this.height / 2); // - Math.sqrt(Math.pow(rad, 2) - (Math.pow(startX - endX, 2)));
var endY:Number = 50;
g.moveTo(startX, startY);
g.lineTo(endX, endY);
g.lineTo(endX + 20, endY);
var textFormat:TextFormat = new TextFormat();
textFormat.color = 0xa1865e;
textFormat.font = creightonEmbeddedFont.fontName;
textFormat.size = 14;
textFormat.letterSpacing = 2;
var text:TextField = new TextField();
text.defaultTextFormat = textFormat;
text.embedFonts = true;
text.text = Math.ceil(progress) + "%";
text.x = endX + 28;
text.y = endY - 14;
text.textColor = 0xa1865e;
text.width = 100;
text.height = 20;
s.addChild(text);
data.draw(s);
return data;
}
public function set ready(value : Boolean) : void
{
this.isReady = value;
this.visible = !this.isReady;
}
public function get ready() : Boolean { return this.isReady; }
}
}