package { import flash.display.Bitmap; public class HotCoffeeView extends TileView { private static const ANIMATION_INTERVAL:Number = 0.4; protected var bitmap2:Bitmap; private var animationTime:Number = 0; private var firstDraw:Boolean = true; public function HotCoffeeView(model:TileModel, layerIndex:int = 0) { super(model, layerIndex); } override public function draw(delta:Number):void { var activeBitmap:Bitmap, lastActiveBitmap:Bitmap; super.draw(delta); if (firstDraw) { switch (TileModel(model).tileType) { case TileModel.TILE_CoffeeHotE1: bitmap2 = new (Embeds.tileForType(TileModel.TILE_CoffeeHotE2))(); break; case TileModel.TILE_CoffeeHotE2: bitmap2 = new (Embeds.tileForType(TileModel.TILE_CoffeeHotE1))(); break; case TileModel.TILE_CoffeeHotS1: bitmap2 = new (Embeds.tileForType(TileModel.TILE_CoffeeHotS2))(); break; case TileModel.TILE_CoffeeHotS2: bitmap2 = new (Embeds.tileForType(TileModel.TILE_CoffeeHotS1))(); break; } bitmap2.x = -bitmap2.width / 2; bitmap2.y = 0; animationTime = Math.random() * ANIMATION_INTERVAL; firstDraw = false; } lastActiveBitmap = int(animationTime / ANIMATION_INTERVAL % 2) ? bitmap2 : bitmap; animationTime += delta; activeBitmap = int(animationTime / ANIMATION_INTERVAL % 2) ? bitmap2 : bitmap; if (activeBitmap != lastActiveBitmap) { removeChild(lastActiveBitmap); addChild(activeBitmap); } } } }