title: AS3 Blitting is Slower than a Movieclip. Why?
body: <p>I tried following a combination of Lee Brimlow's blitting tutorial series and and the technique in Rex Van der spuy's "advanced game design with flash"</p>
  
  <p>I am a developer working on a web online virutal world made in flash. I made a phone application (works similar to the phone in grand theft auto games). Anyway, when a message is sent we want to play this crazy animation of an envelope flying around and transforming with sparkles around it. It was laggy (especially on older computers) so I thought it would be a great chance to use blitting. However, the blitting animation actually plays slower than a regular movieclip!! What the heck is going on here? Is blitting only better for mobile devices and actually slower on computers? Maybe I am doing something wrong. Here is my code:</p>
  
  <p>// THIS PART HAPPENS WHEN PHONE IT INITIALIZED</p>
  
  <pre><code>//**                
  //---------------- Blitting stuff ----------------------------------
  // add this bitmap stage to the display list so we can see it
              _bitmapStage = new BitmapData(550, 400, true, 0xD6D6D6);
  
  
          _phoneItself.addChild(new Bitmap(_bitmapStage));
  
          var _spritesheetClass:Class = getDefinitionByName("ESpritesheet_1") as Class;
          _spritesheet = new _spritesheetClass() as BitmapData;
  
          _envelopeBlit = new BlitSprite(_spritesheet, BlitConfig.envelopeAnimAry , _bitmapStage);
          _envelopeBlit.x = -100;
          _envelopeBlit.y = 0;
  
          _envelopePlayTimer = new Timer(5, 0);
          _envelopePlayTimer.addEventListener(TimerEvent.TIMER, onEnterTimerFrame);
          _envelopeBlit.addEventListener("ENV_ANIM_DONE", onEnvAnimFinished);
  </code></pre>
  
  <p>// a "BlitSprite" is a class that I made. It looks like this:</p>
  
  <pre><code>package com.fs.util_j.blit_utils
  {
      import flash.display.BitmapData;
      import flash.events.Event;
      import flash.events.EventDispatcher;
      import flash.geom.Point;
      import flash.geom.Rectangle;
  
      public class BlitSprite extends EventDispatcher
      {
  
          private var _fullSpriteSheet:BitmapData;
          private var _rects:Array;
          private var _bitmapStage:BitmapData;
  
          private var pos:Point = new Point ();
          public var x:Number = 0;
          public var y:Number = 0;
  
          public var _animIndex:
  </code></pre>
  
  <p>int = 0;
          private var _count:int = 0;</p>
  
  <pre><code>    public var animate:Boolean = true;
      private var _whiteTransparent:BitmapData;
      private var _envelopeAnimAry:Array;
      private var _model:Object;
  
  
  
      public function BlitSprite(fullSpriteSheet:BitmapData, envelopeAnimAry:Array, bitmapStage:BitmapData, model:Object = null) 
      {
          _fullSpriteSheet = fullSpriteSheet;
          _envelopeAnimAry = envelopeAnimAry;
              _bitmapStage = bitmapStage;
              _model= model;
  
              init();
          }
  
          private function init():void
          {
  //          _whiteTransparent = new BitmapData(100, 100, true, 0x80FFffFF);
  
              this.addEventListener("ENV_ANIM_DONE", onEvnAnimDone);
  
          }       
  
          protected function onEvnAnimDone(event:Event):void
          {
  
          }       
  
          public function render():void
          {
  
  //          pos.x = x - _rects[_animIndex].width*.5;
  //          pos.y = y - _rects[_animIndex].width*.5;
  
  //          if (_count % 1 == 0 &amp;&amp; animate == true)
  //          {
  
  //              trace("rendering");
  
                  if (_animIndex == (_envelopeAnimAry.length - 1) )
                  {
  //                  _animIndex = 0;
                      dispatchEvent(new Event("ENV_ANIM_DONE", true));
                      animate = false;
  //                  trace("!!!!animate over " + _model.animOver);
  
  //                  if (_model != null)
  //                  {
  //                      _model.animOver = true;
  //                  }
  
  //                  trace("!!!!animate over " + _model.animOver);
  
                  }
  
                  else 
                  {
                      _animIndex++;
                  }
  
  
                  pos.x = x + _envelopeAnimAry[_animIndex][1];
                  pos.y = y + _envelopeAnimAry[_animIndex][2];
  
  
                  _bitmapStage.copyPixels(_fullSpriteSheet, _envelopeAnimAry[_animIndex][0], pos, null, null, true);
  
          }
  
  
  
      }
  }
  
  
  
  
  // THIS PART HAPPENS WHEN PHONE'S SEND BUTTON IS CLICKED
  
  
                  _envelopeBlit.animate = true;
                  _envelopeBlit._animIndex = 0;
                  _darkSquare.visible = true;
                  _envelopePlayTimer.addEventListener(TimerEvent.TIMER, onEnterTimerFrame);
                  _envelopePlayTimer.start();
  </code></pre>
  
  <p>it also uses BlitConfig which stores the info about the spritesheet spit out by TexturePacker </p>
  
  <pre><code>    package com.fs.pack.phone.configuration
      {
          import flash.geom.Rectangle;
  
          public final class BlitConfig
          {
  
  
  
  
              public static var _sending_message_real_20001:Rectangle = new Rectangle(300,1020,144,102);
              public static var _sending_message_real_20002:Rectangle = new Rectangle(452,1012,144,102);
              public static var _sending_message_real_20003:Rectangle = new Rectangle(852,852,146,102);
              public static var _sending_message_real_20004:Rectangle = new Rectangle(2,1018,146,102);
              public static var _sending_message_real_20005:Rectangle = new Rectangle(702,822,148,102);
  .
  .
  .
  public static var _sending_message_real_20139:Rectangle = new Rectangle(932,144,1,1);
  
      public static var envelopeAnimAry:Array = [
  
                  // rectangle, x offset, y offset
              [ _sending_message_real_20001, 184,155],
              [ _sending_message_real_20002, 184,155],
              [ _sending_message_real_20003, 183,155],
              [ _sending_message_real_20004, 183,155],
  .
  .
  .
  [ _sending_message_real_20139, 0,0]
          ]
  
  
  
          public function BlitConfig()
          {
          }
  
  
      }
  }
  </code></pre>