0 Replies Latest reply on May 27, 2011 2:27 AM by SPGAnne

    why does my pre-loader flicker

    SPGAnne Level 1

      I just installed FlashPlayer 10.3.181 (yeah...I know I've been down level for a while).  The custom preloader I built for my Flex 3 ages and ages ago and has worked forever now flickers and flashes and disappears from the screen.  Why would that be?  How can I make my preloader work properly again?

       

      HELP!!!!!  Here's my code:

       

       

      public class ProgressBar extends Loader{

      [

       

      Bindable]

       

      private var logoClass:Class; //must be set when constructed

       

       

      private var logoBitmap:Bitmap;

       

       

      private var _ready:Boolean;

       

      private var _progress:Number;

       

      private var m_BitmapData:BitmapData;

       

       

      private static var ProgressWidth:int = 150; // Progress bar width

       

       

      private static var LeftMargin:int = 1; // Left Margin

       

       

      private static var RightMargin:int = 2; // Right Margin

       

       

      private static var Spacing:int = 10; // Spacing between logo and progress bar

       

       

      private static var TopMargin:int = 1; // Top Margin

       

       

      private static var BottomMargin:int = 1; // Bottom Margin

       

       

      private static var ProgressHeight:int = 15; // Progress bar height

       

       

       

      private static var ProgressBarBackground:uint = 0xFFFFFF;

       

      private static var progressBarOuterBorder:uint = 0xc4e1ff;

       

      private static var ProgressBarColor:uint = 0x014e98;

       

      private static var ProgressBarInnerColor:uint = 0xFFFFFF;

       

       

      public function ProgressBar(logoClass:Class):void{

       

      super();

       

      this.logoClass = logoClass;

      _progress = 0;

       

      if(logoClass){

      logoBitmap =

      new logoClass as Bitmap;

      }

      }

       

       

      public function refreshProgressBar():void{

      m_BitmapData = drawProgress();

      // Create the bitmapdata object

       

       

      var encoder:PNGEncoder = new PNGEncoder();

       

      var byteArray:ByteArray = encoder.encode(m_BitmapData); // Encode the bitmapdata to a bytearray

       

       

      this.loadBytes(byteArray); // Draw the bitmap on the loader object

      }

       

       

      public function getWidth():Number{

       

      var w:Number = LeftMargin + ProgressWidth + RightMargin;

       

      if(logoBitmap) w += logoBitmap.width + Spacing;

       

      return w;

      }

       

       

      public function getHeight():Number{

       

      var h:Number = TopMargin + BottomMargin;

       

      if(logoBitmap) h += logoBitmap.height;

      h = Math.max(h,20);

       

      return h;

      }

       

      public function getBarX():Number{

       

      var x:Number = LeftMargin;

       

      if(logoBitmap) x += logoBitmap.width + Spacing;

       

      return x;

      }

       

      private function drawProgress():BitmapData{

       

      // Create the bitmap class object

       

      var bitmapData: BitmapData = new BitmapData(getWidth(), getHeight(), true, 0);

       

       

      // Draw the Progress Bar

       

      var sprite:Sprite = new Sprite();

       

      var graph:Graphics = sprite.graphics;

       

       

      // Draw the progress bar background

      graph.beginFill(ProgressBarBackground);

      graph.lineStyle(1, progressBarOuterBorder, 1,

      true);

       

      var containerWidth: Number = ProgressWidth;

       

      var px:int = getWidth() - RightMargin - ProgressWidth;

       

      var py:int = (getHeight() - ProgressHeight) / 2;

      graph.drawRoundRect(px, py, containerWidth, ProgressHeight, 6);

      containerWidth -= 4;

       

      var progressWidth: Number = containerWidth * _progress / 100;

      graph.beginFill(ProgressBarColor);

      graph.lineStyle(1, ProgressBarInnerColor, 1,

      true);

      graph.drawRoundRect(px + 2, py + 2, progressWidth, ProgressHeight - 4, 6);

       

      bitmapData.draw(sprite);

       

       

      //Draw the Logo

       

      if(logoBitmap){

      bitmapData.draw(logoBitmap.bitmapData,

      null, null, null, null, true);

      }

       

      return bitmapData;

      }

       

      public function set ready(value:Boolean): void{

      _ready = value;

       

      this.visible = !value;

      }

       

      public function get ready():Boolean{

       

      return _ready;

      }

       

      public function set progress(value:Number): void{

      _progress = value;

      }

      public

      function get progress():Number{

       

      return _progress;

      }

      }