reflect

by ifree
♥0 | Line 48 | Modified 2013-06-24 01:48:48 | MIT License
play

ActionScript3 source code

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

package {
    import flash.geom.Rectangle;
    import flash.display.Sprite;
    import flash.events.Event;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            // write as3 code here..
            
            addEventListener(Event.ADDED_TO_STAGE,init);          
            mBall=new Ball;
        }
        private var mBall:Ball;
        private var ang:Number;
        private var border:Rectangle;  
        private function init(e:Event):void{
            removeEventListener(Event.ADDED_TO_STAGE,init);   
            if(!stage)
                return;
            this.graphics.lineStyle(1,0x123984)
            border=new Rectangle(10,10,stage.stageWidth-20,stage.stageHeight/2);
            this.graphics.drawRect(10,10,border.width,border.height);
            addChild(mBall);
            mBall.x=mBall.y=100;
            ang=Math.PI/4;
            addEventListener(Event.ENTER_FRAME,loop);           
        }
        
        private function loop(e:Event):void{
            mBall.x+=Math.cos(ang);
            mBall.y+=Math.sin(ang)*3;
            if(mBall.x>border.right){
                ang=Math.PI-ang;
            }else if(mBall.x<border.x){
                ang=Math.PI-ang;
            }else if(mBall.y<border.y)
            {
                ang=-ang;
            }else if(mBall.y>border.bottom){
                ang=-ang;
            }
        }
    }
}
import flash.display.Sprite;

class Ball extends Sprite
{
    
    public function Ball(r:Number=10){
        this.graphics.beginFill(0x00ff00,.8);
        this.graphics.drawCircle(0,0,r);        
    }
        
}