4 Replies Latest reply on Aug 27, 2009 4:41 PM by bmilesp

    Flex4 preloader: cannot change stageWidth and stageHeight to anything but defaults?

    bmilesp Level 1

      I've made a class to extend SparkDownloadProgressBar and added it to the the preloader="" mxml in the <s:Application> tag. the flash object width and height in the html is set to 100%, as well as in the <s:Application> tag. No matter what i set in the application, i can't get the stageWidth and srtageHeight set to anything but the defauts: 500x375. any ideas? here's my code for the SparkDownloadProgressBar class:

       

      package components
      {
          import com.greensock.TweenMax;
          import com.greensock.plugins.TransformAroundCenterPlugin;
          import com.greensock.plugins.TweenPlugin;   
          import flash.display.Sprite;
          import flash.events.Event;
          import flash.events.ProgressEvent;  
          import mx.events.FlexEvent;
          import mx.preloaders.SparkDownloadProgressBar;
      
          public class TJProgressBar extends SparkDownloadProgressBar
          {
              
              private var PreloaderSymbol:Class = TJPreloader; ///from libs/TJProgressBar.swc
              private var _preloaderSymbol:TJPreloader;
              private var _preloader:Sprite;
      
              public function TJProgressBar()
              { 
                  super();
                      TweenPlugin.activate([TransformAroundCenterPlugin])
                  _preloaderSymbol = new PreloaderSymbol(); //in libs TJProgressBar.swc 
                  _preloaderSymbol.does_he.visible = false;               
                   addChild(_preloaderSymbol);  
                   centerPreloader()
                   TweenMax.from(_preloaderSymbol,4,{rotationY:12, onComplete:preloaderComplete})
              }
              
              
              private function centerPreloader():void{
                   trace('centering: '+stageWidth+" "+stageHeight)
                    _preloaderSymbol.x = stageWidth/2;
                   _preloaderSymbol.y = stageHeight/2;  
              }
              
              override public function set preloader(preloader:Sprite):void{
                  _preloader = preloader;
                  _preloader.addEventListener(ProgressEvent.PROGRESS, onDownloadProgress);
                  _preloader.addEventListener(FlexEvent.INIT_COMPLETE, onFlexInitComplete);
              }
       
              private function onDownloadProgress(event:ProgressEvent):void{
                  var percent:Number = (100 * (event.bytesLoaded / event.bytesTotal)) >> 0;
                  _preloaderSymbol.updatePreloader(percent);
              }
       
              private function onFlexInitComplete(event:FlexEvent):void{
                   _preloaderSymbol.does_he.visible = true
                   TweenMax.killTweensOf(_preloaderSymbol)
                   TweenMax.to(_preloaderSymbol,.5,{transformAroundCenter:{rotationY:0}, onComplete:preloaderDelay})
              }
       
              private function preloaderDelay():void{
                  TweenMax.delayedCall(.5,preloaderComplete);
              }
       
                 private function preloaderComplete():void{
                  TweenMax.killTweensOf(_preloaderSymbol)
                  removeChild(_preloaderSymbol);
                  killEventListeners();
                  killObjects();
                  dispatchEvent(new Event(Event.COMPLETE));
              }
       
              private function killEventListeners():void{
                  _preloader.removeEventListener(ProgressEvent.PROGRESS, onDownloadProgress);
                  _preloader.removeEventListener(FlexEvent.INIT_COMPLETE, onFlexInitComplete);
              }
      
              private function killObjects():void{
                   _preloader = null;
                  _preloaderSymbol = null;
                  PreloaderSymbol = null;
              }
              
              // Override to return true so progress bar appears
              // during initialization.       
              override protected function showDisplayForInit(elapsedTime:int, 
                  count:int):Boolean {
                      return true;
              }
      
              // Override to return true so progress bar appears during download.     
              override protected function showDisplayForDownloading(
                  elapsedTime:int, event:ProgressEvent):Boolean {
                      return true;
              }
          }
      
      }