//設(shè)置邊界:上下左右 //var top:Number = 0; var right:Number = stage.stageWidth; //var bottom:Number = stage.stageHeight; var left:Number = 0; //設(shè)置位移:x、y 為水平和垂直軸 var vx:Number = 3; //var vy:Number = 3; //注冊ENTER_FRAM事件偵聽器 addEventListener(Event.ENTER_FRAME, mover); //響應(yīng)函數(shù):負(fù)責(zé)影片的整個(gè)動畫 function mover(e:Event):void { ball.x += vx; //ball.y += vy; if (ball.x < left + ball.width / 2) { vx *= -1; } else if (ball.x > right - ball.width / 2) { ball.x = right - ball.width / 2; vx *= -1; } /*if (ball.y < top + ball.height / 2) { ball.y = top+ball.height / 2; vy *= -1; } else if (ball.y > bottom - ball.height / 2) { ball.y = bottom - ball.height / 2; vy *= -1; }*/ } 設(shè)置邊界: |
|