第1次在Flash Builder中写程序

今天开始正式折腾Flash Builder4.6,整整一天的时间写了个关于小球在屏幕上移动的动画。

发到博客上,算是今天的一个总结吧。

package
{
    import flash.display.Sprite;
    import flash.events.Event;
   
    public class Ex004 extends Sprite
    {
        private var ball:Sprite;
        public function Ex004()
        {
            init();
        }
        private function init():void
        {
            ball=new Sprite();
            addChild(ball);
            ball.graphics.beginFill(0xff0000);
            ball.graphics.drawCircle(0,0,10);
            ball.graphics.endFill();
            ball.x=20;
            ball.y=stage.stageHeight/2
            ball.addEventListener(Event.ENTER_FRAME,onEnterFrame);
               
        }
        private function onEnterFrame(event:Event):void
        {
            ball.x++;
            if(ball.x>100)
            {
                removeChild(ball);
                addChild(ball);
                ball.x=20;
            }
        }
    }
}

 

posted @ 2012-04-03 15:58  surfacetension  阅读(187)  评论(0编辑  收藏  举报