2011-01-10 4 views
0

Je suivais cette page d'aide pour créer un préchargement personnalisé extension Sprite pour charger un fichier SWF d'animation, mais il ne fonctionne pas (l'animation SWF n'affiche pas):Flex 4 personnalisée Preloader ne fonctionne pas

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

Je sais que le fichier Animation.swf est correct, car si je le charge dans l'application principale, il s'affiche et s'exécute.

Le préchargeur fonctionne si une image est chargée par le préchargeur à la place du fichier SWF d'animation.

--------------------- test.mxml (application principale) -----------------

BTW, j'ai généralement beaucoup plus de lignes de ComboBox dans l'application pour forcer le preloader à afficher, mais en limitant le nombre de lignes ici.

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

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

}}

+0

Essayer d'écouter Event.INIT au lieu de Event.COMPLETE sur le chargeur (si vous avez un actioncript dans l'animation). Je ne chargerais pas l'animation à l'exécution pour un préchargeur, j'intégrerais l'animation avec la balise Embed, en spécifiant le symbole de l'animation dans la bibliothèque. Laissez le swf principal se concentrer sur le chargement lui-même à la place. –

Répondre

0

Je me souviens il y a des restrictions durs de votre préchargement personnalisé. It (assets/Animation.swf) devrait être une animation Flash d'exactement 100 diapositives. Probablement cela pourrait être la raison.

Questions connexes