Flex 4自定义预加载器无法正常工作

时间:2011-01-10 06:34:23

标签: flex flex4

我正在关注此帮助页面以创建一个自定义预加载器,用于扩展Sprite以加载动画SWF,但它无效(动画SWF未显示):

http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf 69084-7e3c.html#WS2db454920e96a9e51e63e3d11c0bf62d75-7feb

我知道Animation.swf文件没问题,因为如果我将它加载到主应用程序中,它就会显示并运行。

如果预加载器而不是动画SWF加载图像,预加载器将起作用。

--------------------- test.mxml(主应用)-----------------

顺便说一句,我通常在应用程序中有更多的ComboBox行来强制显示预加载器,但这里限制了行数。

                                                       

--------- customPreloaders.SparkAnimationProgressBar.as ----------------

打包customPreloaders {     import flash.display。;     import 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 {}

} }

1 个答案:

答案 0 :(得分:0)

我记得您的自定义预加载器有严格的限制。 它(assets / Animation.swf)应该是一个完全100张幻灯片的Flash动画。 可能这可能是原因。