package
{
    import com.adobe.viewsource.ViewSource;
    import com.cb.utils.FrameRateCounter;
    
    import flash.display.Sprite;
    import flash.events.Event;
    
    [SWF("ExpandingBox", backgroundColor="#FFFFFF", frameRate="60", width="1000", height="1000")]
    public class ExpandingBox extends Sprite
    {
        private var _canvas:Sprite;
        private var _red:int = 0;
        private var _green:int = 0;
        private var _blue:int = 0;
        private var _width:int = 1;
        private var _height:int = 1;
        private var _direction:int = 1;
        
        public function ExpandingBox()
        {
            ViewSource.addMenuItem(this, "srcview/index.html");  // Used to allow ViewSource
            _canvas = new Sprite();
            _canvas.y = 50;
            this.addChild(_canvas);
            stage.addEventListener(Event.ENTER_FRAME, loop);
            var fps:FrameRateCounter = new FrameRateCounter();
            this.addChild(fps);
        }
        
        private function loop(e:Event):void
        {
            _canvas.graphics.clear();
            _canvas.graphics.beginFill(_red<<16 | _green<<8 | _blue);
            _canvas.graphics.drawRect(0,0,_width,_height);
            
            if(_red < 255 && _blue == 0){
                _red++;
            }else if(_green < 255 && _red == 255){
                _green++;
            }else if(_blue < 255 && _red > 0){
                _red--;
                _blue ++;
            }else if(_green > 0){
                _green--;
            }else {
                _blue--;
            }
            
            if(_width < 1100){
                _width++;
                _height++;
            }
        }
    }
}