我下面這個幫助頁面創建擴展雪碧加載動畫SWF的自定義預加載器,但它不工作(動畫SWF沒有顯示):的Flex 4自定義預加載不工作
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf 69084-7e3c .html#WS2db454920e96a9e51e63e3d11c0bf62d75-7feb
我知道Animation.swf文件沒問題,因爲如果我將它加載到它顯示並運行的主應用程序中。
預加載器在預加載器而不是動畫SWF加載圖像時工作。
--------------------- test.mxml(main app)-----------------
順便說一句,我通常在應用程序中有更多的ComboBox行來強制preloader顯示,但限制這裏的行數。
--------- -------- customPreloaders.SparkAnimationProgressBar.as --------
package customPreloaders { import flash.display。 ; 導入flash.events。; import flash.net。 ; import flash.utils。;
import mx.events.*;
import mx.preloaders.*;
public class SparkAnimationProgressBar extends Sprite
implements IPreloaderDisplay{
// Loader instance to load the animation SWF file.
private var animationLdr:flash.display.Loader;
public function SparkAnimationProgressBar() {
super();
}
// Add event listeners.
public function set preloader(preloader:Sprite):void {
preloader.addEventListener(
ProgressEvent.PROGRESS, handleProgress);
preloader.addEventListener(
Event.COMPLETE, handleComplete);
preloader.addEventListener(
FlexEvent.INIT_PROGRESS, handleInitProgress);
preloader.addEventListener(
FlexEvent.INIT_COMPLETE, handleInitComplete);
}
// Initialize the Loader control in the override
// of IPreloaderDisplay.initialize().
public function initialize():void {
animationLdr = new flash.display.Loader();
animationLdr.contentLoaderInfo.addEventListener(
Event.COMPLETE, loader_completeHandler);
animationLdr.load(new URLRequest("assets/Animation.swf"));
}
// After the SWF file loads, set the size of the Loader control.
private function loader_completeHandler(event:Event):void
{
addChild(animationLdr);
animationLdr.width = 200;
animationLdr.height= 200;
animationLdr.x = 100;
animationLdr.y = 100;
}
// Define empty event listeners.
private function handleProgress(event:ProgressEvent):void {}
private function handleComplete(event:Event):void {}
private function handleInitProgress(event:Event):void {}
private function handleInitComplete(event:Event):void {
var timer:Timer = new Timer(2000,1);
timer.addEventListener(TimerEvent.TIMER, dispatchComplete);
timer.start();
}
private function dispatchComplete(event:TimerEvent):void {
dispatchEvent(new Event(Event.COMPLETE));
}
// IPreloaderDisplay interface methods.
public function get backgroundColor():uint {
return 0;
}
public function set backgroundColor(value:uint):void {}
public function get backgroundAlpha():Number {
return 0;
}
public function set backgroundAlpha(value:Number):void {}
public function get backgroundImage():Object {
return undefined;
}
public function set backgroundImage(value:Object):void {}
public function get backgroundSize():String {
return "";
}
public function set backgroundSize(value:String):void {}
public function get stageWidth():Number {
return 200;
}
public function set stageWidth(value:Number):void {}
public function get stageHeight():Number {
return 200;
}
public function set stageHeight(value:Number):void {}
}}
嘗試在加載器上偵聽Event.INIT而不是Event.COMPLETE(如果在動畫中有任何動作)。我不會在運行時爲預加載器加載動畫,我會用Embed標籤嵌入動畫,在庫中指定動畫的符號。讓主要的swf專注於加載本身。 – 2011-01-10 15:44:25