我有一个简单的城市动画,一辆车从屏幕上穿过,一个球向左滚动。动画由 ENTER_FRAME 事件运行,但我想使用计时器,但我无法弄清楚。这是我的代码:
package {
import flash.display.*;
import flash.events.*;
import flash.utils.*;
public class cityApp extends MovieClip {
function cityApp() {
//TASK 1 : INITIALIZE THE MOVIECLIPS ON STAGE
Car.x = 10;
Ball.x = 500;
Sunset.alpha = 0;
//TASK 2: ADD A LISTENER TO LOOP THROUGH THE FRAME
var atimer:Timer= new Timer(500, 30);
atimer.addEventListener(TimerEvent.TIMER, CityMoves);
}
function CityMoves(event:TimerEvent):void {
//TASK 1:
// A. DRIVE THE CAR ACROSS THE STAGE BY INCREMENTING ITS
// X POSITION BY 2
Car.x += 2;
//B. ROTATE THE WHEELS OF THE CAR
Car.Wheel1.rotation+=3;
Car.Wheel2.rotation+=3;
//TASK 2: MOVE THE BALL IN THE OPPOSITE POSITION OF THE CAR
//ROTATE THE BALL SO THAT IT APPEARS TO BE ROLLING
Ball.x -= 2;
Ball.rotation-= 5;
//TASK 3: THE EVENING SUNSET GRADUALLY APPEARS AS ITS ALPHA INCREASES.
Sunset.alpha += .007;
}
}
} 任何帮助深表感谢。