您的位置:首页 > 其它

小球随机运动

2008-12-29 09:11 288 查看
帧循环(EnterFrame)

代码如下:

1 //Save as BallMove.as

2 package

3 {

4 import flash.display.Sprite;

5 import flash.events.Event;

6

7 public class BallMove extends Sprite

8 {

9 private var ball:Sprite;

10

11 public function BallMove ()

12 {

13 Init ();

14 }

15 public function Init ():void

16 {

17 ball=new Sprite();

18 addChild (ball);

19

20 ball.graphics.beginFill (0xffff00);

21 ball.graphics.drawCircle (0,0,5);

22 ball.graphics.endFill ();

23

24 ball.x=stage.stageWidth/2;

25 ball.y=stage.stageHeight/2;

26

27 ball.addEventListener (Event.ENTER_FRAME,Ball_EnterFrame);

28 }

29 private function Ball_EnterFrame (e:Event):void

30 {

31 ball.x+=(15-30*Math.random());

32 ball.y+=(15-30*Math.random());

33 }

34 }

35 }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: