分享

flex4

 quasiceo 2015-01-12

I am following this help page to create a custom preloader extending Sprite to load an animation SWF, but it is not working (the animation SWF is not displaying):

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

I know the Animation.swf file is okay, because if I load it into the main app it displays and runs.

The preloader works if an image is loaded by the preloader instead of the animation SWF.

--------------------- test.mxml (main app) -----------------

BTW, I typically have many more lines of ComboBox in the app to force the preloader to display, but limiting number of lines here.

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

package 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 {}

} }

asked Jan 10 '11 at 6:34

    
Trying listening for Event.INIT instead of Event.COMPLETE on the loader (If you have any actionscript in the animation). I wouldn't load the animation at runtime for a preloader, I'd embed the animation with the Embed tag, specifying the symbol of the animation in the library. Let the main swf concentrate on loading itself instead. –  Chris Bos Jan 10 '11 at 15:44

1 Answer

I remember there are hard restrictions on your custom preloader. It (assets/Animation.swf) should be a Flash animation of exactly 100 slides. Probably that could be the reason.

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多