flash on 2009-9-25

by telcanty
♥0 | Line 42 | Modified 2009-09-25 10:54:34 | MIT License
play

ActionScript3 source code

/**
 * Copyright telcanty ( http://wonderfl.net/user/telcanty )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/1Dm0
 */

package {
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        
        private var _display:Sprite;
        private var _otherDisplay:Sprite;
        private var _newDisplay:Sprite;

        public function FlashTest() {
            _display = new Sprite();
            _otherDisplay = new Sprite();
            _newDisplay = new Sprite();
            

            //_display.x =1;//stage.stageWidth / 2;
            //_display.y = 100;//stage.stageHeight / 2;

            this.addChild(_display);
           // _display.addChild(_otherDisplay);
           // _otherDisplay.addChild(_newDisplay);
           // _otherDisplay.removeChild(_newDisplay);          
           // _display.addChild(_newDisplay);

            drawLine(_display, 40 , 40 , 100, 400, 0xFF0000);
            //drawSquare(_display, 0,0,200,200,0xFF0000);
            //drawSquare(_display,20,20,210,210, 0xFF0000);
            //drawSquare(_otherDisplay,0,0,100,100, 0x0000FF);
            //drawSquare(_newDisplay,40,40,230,230, 0x00FF00);
        }

        public function drawLine(_obj:Sprite, xStart:Number, yStart:Number, xEnd:Number, yEnd:Number, color:uint = 0x000000):Sprite
        {
             var segmentSize:int = 2;
             var circleSize:int = 1;
             
             _obj.graphics.lineStyle(1,color,1);
             _obj.graphics.moveTo(xStart,yStart);
             _obj.graphics.lineTo(xEnd, yEnd);            

             var yDifference:Number = Math.abs(yEnd - yStart);

             for(var i:int = xStart; i <= xEnd; i += segmentSize)
             {
                var percent:Number = i / xEnd;

                trace("Current X: " + i);
                trace("Current Y: " + y);

                _obj.graphics.beginFill(color);
                _obj.graphics.drawCircle(i, yStart - segmentSize + yDifference * percent , circleSize);
                _obj.graphics.endFill();             
             }

            return _obj;
        }
        
        public function drawSquare(_obj:Sprite, x:Number, y:Number, width:Number, height:Number, color:uint = 0x000000):Sprite
        {
            drawLine(_obj,x,y,width,x, color);
            drawLine(_obj,x,height,width,height, color);
            drawLine(_obj,x,y,x,height, color);
            drawLine(_obj,width,y,width,height, color);
            return _obj;
        }


    }
}